Пример #1
0
        public async Task <IActionResult> Delete(int id)
        {
            var sp = await _repository.GetServiceProviderAsync(id);

            if (sp == null)
            {
                return(NotFound());
            }
            _repository.Delete(sp);
            await _unitOfWork.CompleteAsync();

            return(Ok(id));
        }
Пример #2
0
        public ActionResult DeleteAjax(int id)
        {
            if (!ViewBag.HasAccessToAdminModule && !ViewBag.HasAccessToOtherConfigurationData)
            {
                BaseModel baseModel = new BaseModel();
                baseModel.ErrorMessage = "You are not eligible to do this action";
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, baseModel) }, JsonRequestBehavior.AllowGet));
            }
            //find the serviceprovider in database
            ServiceProvider serviceprovider = serviceproviderRepository.Find(id);

            if (serviceprovider == null)
            {
                //set error message if it does not exist in database
                serviceprovider = new ServiceProvider();
                serviceprovider.ErrorMessage = "ServiceProvider not found";
            }
            else
            {
                try
                {
                    //delete serviceprovider from database
                    serviceproviderRepository.Delete(serviceprovider);
                    serviceproviderRepository.Save();
                    //set success message
                    serviceprovider.SuccessMessage = "ServiceProvider has been deleted successfully";
                }
                catch (CustomException ex)
                {
                    serviceprovider.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    ExceptionManager.Manage(ex);
                    serviceprovider.ErrorMessage = Constants.Messages.UnhandelledError;
                }
            }
            //return action status in json to display on a message bar
            if (serviceprovider.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, serviceprovider) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, serviceprovider) }));
            }
        }