示例#1
0
        public void Delete(long id)
        {
            var phones = _phoneService.Read(id);

            foreach (var phone in phones)
            {
                _phoneService.Delete(phone);
            }
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Phone phone = _phoneService.GetOneById(id);

            _phoneService.Delete(id);
            string url = Url.Action("ListPhones", "Phones", new { Id = phone.PersonId });

            return(Json(new { success = true, url = url, target = "#idPhone" }));
        }
示例#3
0
        public IActionResult Delete(int id)
        {
            var result = phoneService.Delete(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
示例#4
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         _phoneService.Delete(id);
         return(Request.CreateResponse(HttpStatusCode.OK, new SuccessResponse()));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
示例#5
0
 public IActionResult Delete(Phone obj)
 {
     try
     {
         _phoneService.Delete(obj);
         return(new ObjectResult(obj.Id));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
 }
示例#6
0
        public IHttpActionResult DeletePhone(int id)
        {
            Phone phone = _phoneService.GetOneById(id);

            if (phone == null)
            {
                return(NotFound());
            }

            _phoneService.Delete(id);

            return(Ok(phone));
        }
示例#7
0
 public ActionResult Delete(int id, Phone phone)
 {
     try
     {
         _phoneService.Delete(phone);
         _logger.LogInformation("One phone was deleted.");
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
示例#8
0
        public IActionResult Update(int id, List <double> personNum, List <string> personAddress, string title)
        {
            var phone   = _phoneService.GetList(i => i.PersonID == id).Select(i => i.PhoneID).ToList();
            var address = _addressService.GetList(i => i.PersonID == id).Select(i => i.AddressID).ToList();


            if (phone != null)
            {
                foreach (var item in phone)
                {
                    _phoneService.Delete(new Phones {
                        PhoneID = item
                    });
                }
            }

            if (address != null)
            {
                foreach (var item in address)
                {
                    _addressService.Delete(new Addresses {
                        AddressID = item
                    });
                }
            }


            var name = _personService.Get(i => i.PersonID == id);

            name.Title = title;
            _personService.Update(name);


            foreach (var item in personNum)
            {
                _phoneService.Add(new Phones {
                    Number = item, PersonID = id
                });
            }

            foreach (var item in personAddress)
            {
                _addressService.Add(new Addresses {
                    Address = item, PersonID = id
                });
            }



            return(RedirectToAction("Index", "Home"));
        }
示例#9
0
 /// <summary>
 /// Method to delete record
 /// </summary>
 /// <param name="id">record id</param>
 /// <returns></returns>
 public IHttpActionResult Delete(int id)
 {
     try
     {
         var employee = _phoneService.FindBy(t => t.Id == id);
         if (employee == null)
         {
             return(NotFound());
         }
         _phoneService.Delete(employee);
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
     return(Ok());
 }
示例#10
0
        public async Task <IActionResult> DeletePhone(int id)
        {
            try
            {
                _PhoneService.Delete(id);
                int res = await _unitOfWork.SaveChangesAsync();

                if (res > 0)
                {
                    operationResult.Success = true;
                    operationResult.Message = "Delete success";
                    operationResult.Caption = "Delete complete";
                }
            }
            catch (System.Exception ex)
            {
                operationResult.Success = false;
                operationResult.Message = ex.ToString();
                operationResult.Caption = "Delete failed!";
            }
            return(Ok(operationResult));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                var phone = _phoneService.GetPhoneByPhoneId(id);

                if (phone != null)
                {
                    _phoneService.Delete(new Phones
                    {
                        UserId       = phone.UserId,
                        FirstName    = phone.FirstName,
                        LastName     = phone.LastName,
                        Organization = phone.Organization,
                        Title        = phone.Title,
                        MobilePhone  = phone.MobilePhone,
                        HomePhone    = phone.HomePhone,
                        Notes        = phone.Notes,
                        HomeAddress  = phone.HomeAddress,
                        NickName     = phone.NickName,
                        WebSite      = phone.WebSite,
                        BirthDay     = phone.BirthDay,
                        CreatedDate  = phone.CreatedDate,
                        ModifiedDate = phone.ModifiedDate,
                        Status       = true
                    });

                    return(Ok(new ResponseModel <Phones> {
                        Status = true, Message = "Phone deleted.", Object = null
                    }));
                }

                return(Ok(new ResponseModel <Phones> {
                    Status = false, Message = "Phone couldn't found.", Object = null
                }));
            }

            return(ValidationProblem());
        }
示例#12
0
        public HttpResponseMessage Put(int id, [FromBody] CampsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }



            var camp      = Mapper.Map <CampsViewModel, Camp>(model);
            var existCamp = _campService.Find(id);

            existCamp.Phones.Clear();

            foreach (var item in camp.Phones)
            {
                // var find = _campService.Find(c => c.Phones.Any(x => x.PhoneNumber == item.PhoneNumber));
                var item1  = item;
                var result = _phoneService.Find(x => x.PhoneNumber == item1.PhoneNumber);
                _phoneService.Delete(result);
            }
            if (existCamp.AddressId != null)
            {
                var address = _addressService.Find(existCamp.AddressId.Value);
                existCamp.AddressId = null;
                existCamp.Address   = null;
                _addressService.Delete(address);
            }

            try
            {
                _unitOfWork.SaveChanges();

                camp.Address.CityId = camp.Address.City.Id;
                camp.Id             = id;
                camp.CampFacilities = null;
                camp.Galleries      = null;
                camp.Suites         = null;
                camp.Address.City   = null;

                //var existItem = _campService.Find(id);
                //if (existItem == null)
                //{
                //    return Request.CreateResponse(HttpStatusCode.BadRequest);
                //}

                //existItem.Address = camp.Address;


                _campService.Update(camp);


                // db.Entry(camp).State = EntityState.Modified;


                _unitOfWork.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CampExists(id))
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
                else
                {
                    throw;
                }
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
        public async Task <ActionResult> Delete(string id)
        {
            await _phoneService.Delete(id);

            return(Response());
        }