示例#1
0
        public async Task <IActionResult> Postcustomerprofile([FromBody] customerprofileTemp customerprofile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            customerprofile profile = new customerprofile();

            profile.Name        = customerprofile.Name;
            profile.Address     = customerprofile.Address;
            profile.DateOfBirth = customerprofile.DateOfBirth;
            profile.PhoneNumber = customerprofile.PhoneNumber;
            _context.customerprofile.Add(profile);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (customerprofileExists(customerprofile.Name))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("Getcustomerprofile", new { id = customerprofile.Name }, customerprofile));
        }
示例#2
0
        public async Task <IActionResult> Edit([FromRoute] int id, [FromBody] customerprofileTemp customerprofile)
        {
            var customerprofileTuple = await _context.customerprofile.SingleOrDefaultAsync(m => m.CustomerProfileID == id);

            if (customerprofileTuple == null)
            {
                return(NotFound());
            }
            customerprofileTuple.Name        = customerprofile.Name;
            customerprofileTuple.Address     = customerprofile.Address;
            customerprofileTuple.PhoneNumber = customerprofile.PhoneNumber;
            customerprofileTuple.DateOfBirth = customerprofile.DateOfBirth;
            _context.Update(customerprofileTuple);
            _context.SaveChanges();
            return(Ok(customerprofile));
        }