Example #1
0
        public ActionResult Edit(SportsSide.DAL.FACILITY model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = webApi.PutFacility(model);

            if (result == false)
            {
                TempData["Hata"] = "Bir hata oluştu.";
                var facility = webApi.GetFacility(model.FACILITY_ID);
                ViewBag.Areas         = new SelectList(webApi.GetAreas(), "AREA_ID", "AREA_NAME", facility.DISTRICT.CITY.AREA.AREA_ID);
                ViewBag.Cities        = new SelectList(webApi.GetCitiesByAreas(facility.DISTRICT.CITY.AREA.AREA_ID), "CITY_ID", "CITY_NAME");
                ViewBag.Districts     = new SelectList(webApi.GetDistrictsByCities(facility.DISTRICT.CITY.CITY_ID), "DISTRICT_ID", "DISTRICT_NAME");
                ViewBag.FacilityTypes = new SelectList(webApi.GetFacilityTypes(), "FT_ID", "FT_NAME", facility.FACILITY_TYPE);
                return(View(model));
            }

            SportsSide.DAL.FACILITY_PICTURES pictureModel = new SportsSide.DAL.FACILITY_PICTURES();
            pictureModel.F_ID = model.FACILITY_ID;
            webApi.DeleteAllFacilityPicturesFromId(model.FACILITY_ID);
            foreach (var path in picturesPath)
            {
                pictureModel.FP_PICTURE = path;
                result = webApi.PostFacilityPicture(pictureModel);
                if (result == false)
                {
                    TempData["Hata"] = "Bir hata oluştu.";
                    return(View(model));
                }
            }
            if (picturesPath.Count == 0)
            {
                pictureModel.FP_PICTURE = "/img/FacilityPictures/no-photo.gif";
                result = webApi.PostFacilityPicture(pictureModel);
                if (result == false)
                {
                    TempData["Hata"] = "Bir hata oluştu";
                    return(View(model));
                }
            }
            return(RedirectToAction("Index", "Facilities"));
        }