public ActionResult DeleteService(string serviceType)
        {
            // Get the logged in Site ID from the session
            int?SiteID = Session["SiteID"] as int?;

            // if there is none, they can't do anything so redirect to the login page
            if (!SiteID.HasValue)
            {
                return(RedirectToAction("Login", "Account"));
            }

            // start setting up the view model
            DeleteServiceViewModel vm = new DeleteServiceViewModel();

            vm.SiteID = SiteID.Value;

            // now find out if this siteID has a service of the specified type
            string sql = null;

            // determine if service is found at site
            switch (serviceType.ToLower())
            {
            case "foodbank":
                sql            = String.Format("SELECT COUNT(SiteID) FROM foodbank WHERE SiteID = {0}", SiteID.Value);
                vm.ServiceType = "Food Bank";
                break;

            case "foodpantry":
                sql            = String.Format("SELECT COUNT(SiteID) FROM foodpantry WHERE SiteID = {0}", SiteID.Value);
                vm.ServiceType = "Food Pantry";
                break;

            case "shelter":
                sql            = String.Format("SELECT COUNT(SiteID) FROM shelter WHERE SiteID = {0}", SiteID.Value);
                vm.ServiceType = "Shelter";
                break;

            case "soupkitchen":
                sql            = String.Format("SELECT COUNT(SiteID) FROM soupkitchen WHERE SiteID = {0}", SiteID.Value);
                vm.ServiceType = "Soup Kitchen";
                break;

            default:
                throw new Exception("SiteController.DeleteService: non-supported serviceType");
            }

            int count = int.Parse(SqlHelper.ExecuteScalar(sql).ToString());

            if (count > 0)
            {
                vm.ServiceExists = true;
            }

            return(View(vm));
        }
        public async Task <IActionResult> Delete(DeleteServiceViewModel model)
        {
            var success = await this.servicesService.RemoveAsync(model.Id);

            if (!success)
            {
                return(this.RedirectToAction("Error", "Home")); // TODO: redirect
            }

            return(this.RedirectToAction("All", "Services"));
        }
Beispiel #3
0
        public async Task <IActionResult> Delete(DeleteServiceViewModel input)
        {
            if (!this.servicesService.CheckIfServiceExists(input.Id))
            {
                return(this.NotFound());
            }

            await this.servicesService.DeleteAsync(input.Id);

            return(this.RedirectToAction("Details", "Categories", new { id = input.CategoryId }));
        }
        public ActionResult DeleteService(string serviceType, DeleteServiceViewModel vm)
        {
            // first thing need is to see if this is the last service for the given Site. if
            // so the user is not allowed to delete it so show an error message.

            string sql = String.Format(
                "SELECT COUNT(comb.SiteID) from " +
                "(SELECT fb.SiteID FROM foodbank fb WHERE fb.SiteID = {0} UNION ALL " +
                " SELECT fp.SiteID FROM foodpantry fp WHERE fp.SiteID = {0} UNION ALL " +
                " SELECT s.SiteID FROM shelter s WHERE s.SiteID = {0} UNION ALL " +
                " SELECT sk.SiteID FROM soupkitchen sk WHERE sk.SiteID = {0}) comb; ", vm.SiteID);

            int numberOfServices = Int32.Parse(SqlHelper.ExecuteScalar(sql).ToString());

            if (numberOfServices.Equals(1))
            {
                vm.ServiceExists = true;
                vm.ErrorMessage  = "Error: The last service for a site cannot be deleted. Please contact the system admin to delete your site.";
            }
            else
            {
                string sql2 = null;

                switch (serviceType.ToLower())
                {
                case "foodbank":
                    sql2 = String.Format("DELETE FROM foodbank WHERE SiteID = {0}", vm.SiteID);
                    break;

                case "foodpantry":
                    sql2 = String.Format("DELETE FROM foodpantry WHERE SiteID = {0}", vm.SiteID);
                    break;

                case "shelter":
                    sql2 = String.Format("DELETE FROM shelter WHERE SiteID = {0}", vm.SiteID);
                    break;

                case "soupkitchen":
                    sql2 = String.Format("DELETE FROM soupkitchen WHERE SiteID = {0}", vm.SiteID);
                    break;

                default:
                    throw new Exception("SiteController.DeleteService: non-supported serviceType");
                }

                SqlHelper.ExecuteNonQuery(sql2);

                vm.DeleteCompleted = true;
            }

            return(View(vm));
        }
        public IActionResult Delete(int id)
        {
            ServiceServiceModel service = this.servicesService.GetById(id);

            if (service.Name == null)
            {
                return(this.BadRequest());
            }

            var model = new DeleteServiceViewModel
            {
                Id               = service.Id,
                Name             = service.Name,
                Price            = service.Price,
                Description      = service.Description,
                ServiceType      = service.ServiceType,
                VehicleType      = service.VehicleType,
                IsShownInSubMenu = (service.IsShownInSubMenu == true) ? "Да" : "Не",
                //TODO: add operating locations and documents tables
            };

            return(this.View(model));
        }