示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("AddressId,AddressLine,City,Pin")] PAddress pAddress)
        {
            if (id != pAddress.AddressID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pAddress);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PAddressExists(pAddress.AddressID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pAddress));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("AddressId,AddressLine,City,Pin")] PAddress pAddress)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pAddress));
        }
 public IHttpActionResult AddAddress([FromBody] PAddress address)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         _addressRepository.Add(address);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(Ok(address));
 }
 public IHttpActionResult UpdateAddress(int id, [FromBody] PAddress address)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (address == null)
     {
         return(BadRequest("User is null"));
     }
     if (id != address.UserID)
     {
         return(BadRequest());
     }
     _addressRepository.Update(address);
     return(Ok(address));
 }
 public IHttpActionResult DeletAddress(int id)
 {
     try
     {
         PAddress address = _addressRepository.Get(id);
         if (address == null)
         {
             return(NotFound());
         }
         _addressRepository.Delete(id);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(Ok("Record is deleted!"));
 }