isotonicq

Back

Oct 28th, 2018
131
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using ManagmentWebPanel.Interfaces.Operator;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. using WebApi.Context.Models.Operator;
  6. using WebApi.Context.Enums.Operator;
  7.  
  8. namespace ManagmentWebPanel.Pages.Operators
  9. {
  10.     public class AddOperatorModel : PageModel
  11.     {
  12.         private readonly IWriteOperator _writeOperatorService;
  13.         private readonly IReadOperator _readOperatorService;
  14.  
  15.         public AddOperatorModel(IWriteOperator writeOperatorService, IReadOperator readOperatorService)
  16.         {
  17.             _writeOperatorService = writeOperatorService;
  18.             _readOperatorService = readOperatorService;
  19.         }
  20.  
  21.         public void OnGet()
  22.         {
  23.  
  24.         }
  25.  
  26.         public IActionResult OnPostOperator([FromBody] Operator postOperator)
  27.         {
  28.             postOperator.CreationDate = DateTime.Now;
  29.             postOperator.Guid = Guid.NewGuid();
  30.            
  31.             foreach (var email in postOperator.Emails)
  32.             {
  33.                 email.CreationDate = DateTime.Now;
  34.                 email.Guid = Guid.NewGuid();
  35.             }
  36.  
  37.             foreach (var phone in postOperator.PhoneNumbers)
  38.             {  
  39.                 phone.CreationDate = DateTime.Now;
  40.                 phone.Guid = Guid.NewGuid();
  41.             }
  42.  
  43.             if (_writeOperatorService.PostOperator(postOperator))
  44.             {
  45.                 return new OkResult();
  46.             }
  47.  
  48.             return new BadRequestResult();
  49.         }
  50.     }
  51. }
RAW Paste Data