Ejemplo n.º 1
0
        public async Task <ActionResult> Edit([Bind(Include = "id,name,zipcode,description,isActive,created_at")] city city)
        {
            if (ModelState.IsValid)
            {
                city.updated_at      = DateTime.Now;
                db.Entry(city).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(city));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "id,parentId,name,subheading,description,isActive,created_at")] CategeogySubCategory categeogySubCategory, string Cat_SubCat)
        {
            if (ModelState.IsValid)
            {
                categeogySubCategory.updated_at      = DateTime.Now;
                db.Entry(categeogySubCategory).State = EntityState.Modified;
                await db.SaveChangesAsync();

                if (String.IsNullOrEmpty(Cat_SubCat))
                {
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("SubCategory"));
            }
            return(View(categeogySubCategory));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(spa_VM model)
        {
            try
            {
                spa_basic_info objBasicInfo = db.spa_basic_info.Include(x => x.spa_images).Include(x => x.spa_prices.Select(a => a.CategeogySubCategory)).Include(x => x.spa_time).Where(x => x.id == model.basic_info.id).FirstOrDefault();

                if (objBasicInfo == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                DateTime nowDt = DateTime.Now;
                //Spa basic info.

                objBasicInfo.name          = model.basic_info.name;
                objBasicInfo.cityId        = model.basic_info.cityId;
                objBasicInfo.address       = model.basic_info.address;
                objBasicInfo.zipcode       = model.basic_info.zipcode;
                objBasicInfo.info_about    = model.basic_info.info_about;
                objBasicInfo.is_active     = model.basic_info.is_active;
                objBasicInfo.contact_name  = model.basic_info.contact_name;
                objBasicInfo.contact_email = model.basic_info.contact_email;
                objBasicInfo.contact_no    = model.basic_info.contact_no;
                objBasicInfo.updated_at    = nowDt;


                //Spa Prices
                Intcheckboxmodel chkModel;
                //Update spa prices and select all deleted prices.
                List <spa_prices> lstSpaPrices = new List <spa_prices>();
                objBasicInfo.spa_prices.ToList().ForEach(x =>
                {
                    //This will update existing prices
                    chkModel = model.Selectedprices.Where(e => e.Id == x.cat_id && e.isChecked).SingleOrDefault();
                    if (chkModel != null)
                    {
                        if (String.IsNullOrEmpty(chkModel.prices))
                        {
                            x.price = null;
                        }
                        else
                        {
                            x.price = Convert.ToDecimal(chkModel.prices);
                        }
                    }
                    else
                    {
                        lstSpaPrices.Add(x);
                        db.Entry(x).State = EntityState.Deleted;
                    }
                });
                //Remove spa prices.

                /*if (lstSpaPrices.Count > 0)
                 * {
                 *  lstSpaPrices.ForEach(x => objBasicInfo.spa_prices.Remove(x));
                 *  db.spa_prices.RemoveRange(lstSpaPrices);
                 *  db.Entry(objBasicInfo.spa_prices.Where(x => x.id == 2)).State = EntityState.Deleted;
                 * }*/
                //Add spa prices
                foreach (var item in model.Selectedprices)
                {//This for loop addes newly added sub category prices.
                    if (item.isChecked && !objBasicInfo.spa_prices.Any(x => x.cat_id == item.Id))
                    {
                        if (String.IsNullOrEmpty(item.prices))
                        {
                            objBasicInfo.spa_prices.Add(new spa_prices {
                                cat_id = item.Id, created_at = nowDt, updated_at = nowDt
                            });
                        }
                        if (!String.IsNullOrEmpty(item.prices))
                        {
                            objBasicInfo.spa_prices.Add(new spa_prices {
                                cat_id = item.Id, price = Convert.ToDecimal(item.prices), created_at = nowDt, updated_at = nowDt
                            });
                        }
                    }
                }

                //Clean up deleted category from spa prices
                List <long>       Dd_catId     = db.CategeogySubCategories.Where(x => x.isActive).Select(x => x.id).ToList();
                List <spa_prices> deletedCatId = objBasicInfo.spa_prices.Where(x => !Dd_catId.Contains(x.cat_id)).ToList();
                if (deletedCatId.Count > 0)
                {
                    db.spa_prices.RemoveRange(deletedCatId);
                }

                //Spa timings.
                //objBasicInfo.spa_time.Join(model.timings, x => x.week_day, j => j.week_day, (x, j) => { x.frm_to_times = j.frm_to_times; return x; });
                objBasicInfo.spa_time.ToList().ForEach(x => x.frm_to_times = model.timings.Where(a => a.week_day == x.week_day).SingleOrDefault().frm_to_times);

                //SPA Images
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName  = Path.GetFileNameWithoutExtension(file.FileName);
                        var Extension = Path.GetExtension(file.FileName);
                        while (System.IO.File.Exists(Server.MapPath("~/UploadImages/") + fileName + Extension))
                        {
                            fileName = fileName + "_" + DateTime.Now.Ticks.ToString();
                        }
                        var path = Path.Combine(Server.MapPath("~/UploadImages/"), fileName + Extension);
                        file.SaveAs(path);
                        objBasicInfo.spa_images.Add(new spa_images()
                        {
                            image_url = "~/UploadImages/" + fileName + Extension, created_at = nowDt, updated_at = nowDt
                        });
                    }
                }
                string querysql = "";
                db.Database.Log = (s) => { querysql += " \r\n " + s; };
                db.Entry(objBasicInfo).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.sqlQuery = querysql;

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                spa_VM objSpaVm = getSpaVMFromSpaBasicInfo(model.basic_info.id);
                ViewBag.citylst = getCityList();
                return(View(objSpaVm));
            }
        }