コード例 #1
0
        public override async Task <AddressAdditionResponse> AddUserAddress(AddressAdditionRequest request, ServerCallContext context)
        {
            // var userAddress = new AddressData { Name = request.Name, Address = request.Address, Enrollment = request.Enrollment };
            var userAddress = GetAddressData(request);

            _personDbContext.Add(userAddress);
            await _personDbContext.SaveChangesAsync();

            var results = new AddressAdditionResponse {
                Message = "Address Save Successfully."
            };

            return(results);
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("PersonId,FirstName,LastName,BirthDate,IsApproved,Role")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Title,Age,Address,City,Phone,Email")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("PId,PName,PAge")] Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Add(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
コード例 #5
0
        public override async Task <AddressAdditionResponse> AddUserAddress(AddressAdditionRequest request, ServerCallContext context)
        {
            var userAddress = GetAddressData(request);

            try
            {
                if (userAddress.Enrollment == "Bank")
                {
                    var trailer = new Metadata()
                    {
                        { "BadValue", "Enrollment type is Bank" },
                        { "Field", "Enrollment" },
                        { "Message", "Bank enrollment is stopped temporarily" }
                    };
                    throw new RpcException(new Status(StatusCode.Cancelled, "Bank enrollment is stopped temporarily"), trailer);
                }
                _personDbContext.Add(userAddress);
                await _personDbContext.SaveChangesAsync();
            }
            catch (InvalidOperationException)
            {
                var trailer = new Metadata()
                {
                    { "CorelationId", Guid.NewGuid().ToString() },
                    { "Message", "Unable to save the Data inside Database." }
                };
                throw new RpcException(new Status(StatusCode.Internal, "Internal Error"), trailer);
            }
            catch (RpcException rpcError)
            {
                throw rpcError;
            }

            var results = new AddressAdditionResponse {
                Message = "Address Save Successfully."
            };

            return(results);
        }
コード例 #6
0
 public void AddItem(Person item)
 {
     try
     {
         var person = new Person()
         {
             SurName      = item.SurName,
             FirstName    = item.FirstName,
             EmailAddress = item.EmailAddress,
             Gender       = item.Gender,
             DateOfBirth  = item.DateOfBirth,
             PhoneNumber  = item.PhoneNumber
         };
         _personDbContext.Add(person);
         _personDbContext.SaveChanges();
         _logger.LogInformation($"Successfully created item with  with  name {item.FirstName} {item.SurName}");
     }
     catch (Exception ex)
     {
         _logger.LogError($"An error occured while adding item with  name {item.FirstName} {item.SurName} . Exception details :{ex.Message}");
     }
 }
コード例 #7
0
 public void CreatePerson(Person NewPerson)
 {
     using var db = new PersonDbContext();
     db.Add(NewPerson);
     db.SaveChanges();
 }
コード例 #8
0
 public void SavePerson(PersonModel person)
 {
     _context.Add(person);
     _context.SaveChanges();
 }