// GET: Admin/spa/Create public ActionResult Create() { spa_VM objSpaVm = new spa_VM(); objSpaVm.categoryLst = getCatSubCatList(); objSpaVm.timings = getSpatimeLst(); ViewBag.citylst = getCityList(); return(View(objSpaVm)); }
// GET: Admin/spa/Details/5 public ActionResult Details(int id) { if (!db.spa_basic_info.Any(x => x.id == id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } spa_VM objSpaVm = getSpaVMFromSpaBasicInfo(id); ViewBag.citylst = getCityList(); return(View(objSpaVm)); }
public ActionResult GetSubCategory(List <long> cat_id, int spa_id) { spa_VM objSpaVm = new spa_VM(); string querysql = ""; db.Database.Log = (s) => { querysql += " \r\n " + s; }; //objSpaVm.Selectedprices = db.CategeogySubCategories.Where(x => cat_id.Contains(x.parentId ?? 0) && x.isActive).Select(x => new Intcheckboxmodel { Id = x.id, isChecked = false, name = x.name }).ToList(); objSpaVm.Selectedprices = getSpaPriceLst(cat_id, spa_id); //ViewBag.sqlQuery = querysql; return(PartialView("subcatePrice", objSpaVm)); }
private spa_VM getSpaVMFromSpaBasicInfo(long spaId) { spa_VM objSpaVm = new spa_VM(); objSpaVm.categoryLst = getCatSubCatList(); objSpaVm.timings = getSpatimeLst(); db.Configuration.LazyLoadingEnabled = false; 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 == spaId).FirstOrDefault();//.Include("spa_images").Include("spa_prices"); objSpaVm.categoryLst.Where(x => objBasicInfo.spa_prices.Any(e => e.CategeogySubCategory.parentId == x.Id)).ToList().ForEach(item => item.isChecked = true); objSpaVm.timings.ForEach(x => x.frm_to_times = objBasicInfo.spa_time.First(a => a.week_day == x.week_day).frm_to_times); if (objBasicInfo != null) { objSpaVm.basic_info = objBasicInfo; objSpaVm.images = objBasicInfo.spa_images.ToList(); //objSpaVm.Selectedprices = objBasicInfo.spa_prices.ToList().Select(x => new Intcheckboxmodel { Id = x.cat_id, name = x.CategeogySubCategory.name, isChecked = true, prices = x.price }).ToList(); objSpaVm.Selectedprices = getSpaPriceLst(objSpaVm.categoryLst.Where(x => x.isChecked).Select(x => x.Id).ToList(), spaId); } return(objSpaVm); }
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)); } }
public ActionResult Create(spa_VM model) { try { DateTime nowDt = DateTime.Now; //Spa basic info. spa_basic_info objBasicInfo = new spa_basic_info() { name = model.basic_info.name, cityId = model.basic_info.cityId, address = model.basic_info.address, zipcode = model.basic_info.zipcode, info_about = model.basic_info.info_about, is_active = model.basic_info.is_active, contact_name = model.basic_info.contact_name, contact_email = model.basic_info.contact_email, contact_no = model.basic_info.contact_no, created_at = nowDt, updated_at = nowDt }; //Spa Prices foreach (var item in model.Selectedprices) { if (item.isChecked) { 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 }); } } } //Spa timings. foreach (var item in model.timings) { objBasicInfo.spa_time.Add(new spa_time { week_day = item.week_day, frm_to_times = item.frm_to_times, created_at = nowDt, updated_at = nowDt }); } //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 }); } } db.spa_basic_info.Add(objBasicInfo); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); spa_VM objSpaVm = new spa_VM(); objSpaVm.categoryLst = getCatSubCatList(); objSpaVm.timings = getSpatimeLst(); ViewBag.citylst = getCityList(); return(View(objSpaVm)); } }