public PartialViewResult Edit(string id) { CategoriesModels model = GetDetail(id); //model.GetListProductType(); return(PartialView("_Edit", model)); }
public ActionResult Create() { CategoriesModels model = new CategoriesModels(); model.IsActive = true; model.IsFreeTrial = true; model.Type = (byte)Commons.EType.NuPOS; return(PartialView("Create", model)); }
public ActionResult Create() { CategoriesModels model = new CategoriesModels(); //model.GetListProductType(); model.ProductTypeID = model.ListProductType.Where(w => w.Text.ToLower().Trim() == Commons.EProductType.Dish.ToString().ToLower().Trim()).Select(s => s.Value).FirstOrDefault(); model.IsIncludeNetSale = true; return(View(model)); }
// GET: Categories public ActionResult IndexCategories() { ApplicationNameMongoDB db = new ApplicationNameMongoDB(); var categories = db.GetAllCategories(); CategoriesModels model = new CategoriesModels(); model.EntityList = categories.ToList(); return(View(model)); }
public ActionResult AddCategory() { ApplicationNameMongoDB db = new ApplicationNameMongoDB(); var categories = db.GetAllCategories(); CategoriesModels model = new CategoriesModels(); model.EntityList = categories.ToList(); ViewBag.Categories = model; return(View()); }
public bool InsertOrUpdateCategories(CategoriesModels model, ref string msg) { try { CategoriesApiModels paraBody = new CategoriesApiModels(); paraBody.AppKey = Commons.AppKey; paraBody.AppSecret = Commons.AppSecret; paraBody.CreatedUser = Commons.CreateUser; paraBody.RegisterToken = new RegisterTokenModels(); paraBody.ID = model.ID; paraBody.StoreID = model.StoreID; paraBody.Name = model.Name; paraBody.Sequence = model.Sequence; paraBody.Description = model.Description; paraBody.TotalProducts = model.TotalProducts; paraBody.ImageURL = model.ImageURL; paraBody.ParentID = model.ParentID; paraBody.ProductTypeID = model.ProductTypeID; paraBody.Type = model.Type; paraBody.IsShowInReservation = model.IsShowInReservation; paraBody.IsShowInKiosk = model.IsShowInKiosk; paraBody.IsGiftCard = model.IsGiftCard; paraBody.IsIncludeNetSale = model.IsIncludeNetSale; paraBody.GLAccountCode = model.GLAccountCode; //==================== NSLog.Logger.Info("InsertOrUpdateCategories Request", paraBody); var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.CreateOrEditCategories, null, paraBody); NSLog.Logger.Info("InsertOrUpdateCategories Result", result); if (result != null) { if (result.Success) { return(true); } else { msg = result.Message; return(false); } } else { return(false); } } catch (Exception e) { NSLog.Logger.Error("InsertOrUpdateCategories Error", e); return(false); } }
// Create Catagory public bool InsertOrUpdateCategory(CategoriesModels model, string userid, ref string msg) { try { RequestCategoriesModels paraBody = new RequestCategoriesModels(); paraBody.CreatedUser = userid; paraBody.ID = model.Id; paraBody.CategoryDetail = model; paraBody.IsConfirm = model.IsConfirm; NSLog.Logger.Info("Update Category Request", paraBody); //==================== var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CategoryAPICreateOrEdit, null, paraBody); NSLog.Logger.Info("Update Category Request", result); if (result != null) { if (result.Success) { return(true); } else { msg = result.Message; NSLog.Logger.Info("CategoryCreateorEdit", result.Message); return(false); } } else { NSLog.Logger.Info("CategoryCreateorEdit", result); return(false); } } catch (Exception e) { NSLog.Logger.Error("CategoryInsertOrUpdate_Fail", e); return(false); } }
public ActionResult Delete(CategoriesModels model) { try { string msg = ""; var result = _factory.DeleteCategories(model.ID, ref msg); if (!result) { ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { _logger.Error("Categories_Delete: " + ex); ModelState.AddModelError("Name", CurrentUser.GetLanguageTextFromKey("An error has occurred when deleting"));// "Have an error when you delete a Categories"); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } }
public ActionResult Delete(CategoriesModels model) { try { string msg = ""; var result = _factory.Delete(model.Id, CurrentUser.UserId, ref msg); if (!result) { //ModelState.AddModelError("Name", Commons.ErrorMsg); ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception ex) { NSLog.Logger.Error("Category_Delete: ", ex); ModelState.AddModelError("Name", Commons.ErrorMsg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Delete", model)); } }
public CategoriesModels GetDetail(string id) { try { CategoriesModels model = _factory.GetListCategory(null, id)[0]; model.ProductTypeName = _productTypeFactory.GetProductTypeName(model.Type); model.ImageURL = string.IsNullOrEmpty(model.ImageURL) ? Commons.Image100_100 : model.ImageURL; if (!string.IsNullOrEmpty(model.ParentID) || CurrentUser.GetLanguageTextFromKey(model.ProductTypeName).Equals(CurrentUser.GetLanguageTextFromKey("Dish"))) { //model.ListCategories = GetSelectListParentCategory(model.StoreID, model.ProductTypeID, id); // Updated 09082017 sort by parent // No include list cate child of current cate model.lstCateGroup = GetSelectListParentCategorySortForEditCate(model.StoreID, model.ProductTypeID, id, model.ParentID); } return(model); } catch (Exception ex) { _logger.Error("Categories_Detail: " + ex); return(null); } }
// Get Detail public CategoriesModels GetDetail(string ID) { CategoriesModels CategoryDTO = new CategoriesModels(); try { RequestCategoriesModels paraBody = new RequestCategoriesModels(); paraBody.ID = ID; NSLog.Logger.Info("GetDetail Category Request", paraBody); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.CategoryAPIGetDetail, null, paraBody); NSLog.Logger.Info("GetDetail Category Request", result); dynamic data = result.Data; var lstDataRaw = data["CategoryDetail"]; var lstContent = JsonConvert.SerializeObject(lstDataRaw); CategoryDTO = JsonConvert.DeserializeObject <CategoriesModels>(lstContent); NSLog.Logger.Info("CategoryGetDetail", CategoryDTO); return(CategoryDTO); } catch (Exception ex) { NSLog.Logger.Error("CategoryGetDetail_Fail", ex); return(null); } }
public ActionResult Create(CategoriesModels model) { try { if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", "Name field is required"); } if (string.IsNullOrEmpty(model.ShortDescription)) { ModelState.AddModelError("ShortDescription", "Short Description field is required"); } if (model.PictureUpload != null && !Commons.ImageExtendFiler.Contains(model.PictureUpload.ContentType)) { ModelState.AddModelError("PictureUpload", Commons.ErrorMsgFilterImage); } if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("Create", model)); } byte[] photoByte = null; if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[model.PictureUpload.ContentLength]; model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength); model.PictureByte = imgByte; model.ImageURL = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName); model.PictureUpload = null; photoByte = imgByte; } string msg = ""; var tmp = model.PictureByte; model.PictureByte = null; bool result = _factory.InsertOrUpdateCategory(model, CurrentUser.UserId, ref msg); if (result) { model.PictureByte = tmp; //Save Image on Server if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null) { var originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\"))); var path = string.Format("{0}{1}", originalDirectory, model.ImageURL); MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length); ms.Write(photoByte, 0, photoByte.Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte); model.PictureByte = photoByte; FTP.Upload(model.ImageURL, model.PictureByte); ImageHelper.Me.TryDeleteImageUpdated(path); } return(RedirectToAction("Index")); } else { //ModelState.AddModelError("Name", Commons.ErrorMsg /*msg*/); if (!string.IsNullOrEmpty(msg) && msg.Equals("There is already one category with the same product type that allows trial version. Do you want to change it?")) { model.IsConfirm = true; } else { model.IsConfirm = false; ModelState.AddModelError("Error", msg); } Response.StatusCode = (int)HttpStatusCode.BadRequest; //return View(model); return(PartialView("Create", model)); } } catch (Exception ex) { NSLog.Logger.Error("Category_Create : ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ActionResult Edit(CategoriesModels model) { try { if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", "Name field is required"); } if (string.IsNullOrEmpty(model.ShortDescription)) { ModelState.AddModelError("ShortDescription", "Short Description field is required"); } if (model.PictureUpload != null && !Commons.ImageExtendFiler.Contains(model.PictureUpload.ContentType)) { ModelState.AddModelError("PictureUpload", Commons.ErrorMsgFilterImage); } if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } byte[] photoByte = null; if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[model.PictureUpload.ContentLength]; model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength); model.PictureByte = imgByte; model.ImageURL = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName); model.PictureUpload = null; photoByte = imgByte; } else { if (!string.IsNullOrEmpty(model.ImageURL)) { model.ImageURL = model.ImageURL.Replace(Commons.PublicImages, "").Replace(Commons.Image100_50, ""); } } string msg = ""; var tmp = model.PictureByte; model.PictureByte = null; bool result = _factory.InsertOrUpdateCategory(model, CurrentUser.UserId, ref msg); if (result) { model.PictureByte = tmp; ////Save Image on Server if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null) { var originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\"))); var path = string.Format("{0}{1}", originalDirectory, model.ImageURL); MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length); ms.Write(photoByte, 0, photoByte.Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte); model.PictureByte = photoByte; FTP.Upload(model.ImageURL, model.PictureByte); ImageHelper.Me.TryDeleteImageUpdated(path); } return(RedirectToAction("Index")); } else { model = _factory.GetDetail(model.Id); //ModelState.AddModelError("Name", Commons.ErrorMsg /*msg*/); ModelState.AddModelError("Error", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { NSLog.Logger.Error("Category_Edit: ", ex); //ModelState.AddModelError("Name", Commons.ErrorMsg); ModelState.AddModelError("Error", Commons.ErrorMsg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } }
public PartialViewResult Edit(string id) { CategoriesModels model = _factory.GetDetail(id); return(PartialView("_Edit", model)); }
public ActionResult Create(CategoriesModels model) { try { byte[] photoByte = null; //model.GetListProductType(); //if (model.ListStoreId.Count < 0) //{ // ModelState.AddModelError("StoreID", " Please choose Store"); //} if (model.ParentID != null) { var parentName = model.ListProductType.Find(x => x.Value.Equals(model.Type.ToString())).Text.ToLower(); if (!CurrentUser.GetLanguageTextFromKey(parentName).Equals(CurrentUser.GetLanguageTextFromKey("dish"))) { model.ParentID = null; } } //if (string.IsNullOrEmpty(model.Name)) //{ // //model.ListCategories = GetSelectListParentCategory(model.StoreID, model.ProductTypeID); // ModelState.AddModelError("Name", "Name field is required"); //} //if (model.Type.ToString() == Commons.EProductType.Dish.ToString("d")) //{ // if (string.IsNullOrEmpty(model.ParentID)) // { // model.ListCategories = GetSelectListParentCategory(model.StoreID, model.Type.ToString()); // ModelState.AddModelError("ParentID", "Parent category field is required"); // } //} string ProductTypeText = ""; if (model.ListProductType != null && model.ListProductType.Count > 0) { ProductTypeText = model.ListProductType.Where(w => w.Value.Trim() == model.Type.ToString().Trim()).Select(s => s.Text).FirstOrDefault(); if (ProductTypeText.Trim().ToLower() != Commons.EProductType.Dish.ToString().Trim().ToLower()) { model.GLAccountCode = null; model.IsGiftCard = false; model.IsIncludeNetSale = false; model.ParentName = ""; model.ParentID = null; } } if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[model.PictureUpload.ContentLength]; model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength); model.PictureByte = imgByte; model.ImageURL = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName); model.PictureUpload = null; photoByte = imgByte; } if (!ModelState.IsValid) { if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0) { model.ImageURL = ""; } //model.ListCategories = GetSelectListParentCategory(model.StoreID, model.Type.ToString()); // Updated 09082017 sort by parent model.lstCateGroup = GetSelectListParentCategorySort(model.StoreID, model.Type.ToString()); if (!string.IsNullOrEmpty(model.ParentID)) { var cateChoose = model.lstCateGroup.Where(w => w.Id == model.ParentID).FirstOrDefault(); if (cateChoose != null) { cateChoose.Selected = true; } } return(View(model)); } //==================== string msg = ""; var tmp = model.PictureByte; model.PictureByte = null; bool result = _factory.InsertOrUpdateCategories(model, ref msg); if (result) { model.PictureByte = tmp; //Save Image on Server if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null) { var originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", Server.MapPath(@"\"))); var path = string.Format("{0}{1}", originalDirectory, model.ImageURL); MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length); ms.Write(photoByte, 0, photoByte.Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte); model.PictureByte = photoByte; FTP.Upload(model.ImageURL, model.PictureByte); ImageHelper.Me.TryDeleteImageUpdated(path); } return(RedirectToAction("Index")); } else { ModelState.AddModelError("Name", msg); // Updated 09082017 sort by parent model.lstCateGroup = GetSelectListParentCategorySort(model.StoreID, model.Type.ToString()); if (!string.IsNullOrEmpty(model.ParentID)) { var cateChoose = model.lstCateGroup.Where(w => w.Id == model.ParentID).FirstOrDefault(); if (cateChoose != null) { cateChoose.Selected = true; } } return(View(model)); } } catch (Exception ex) { _logger.Error("Categories_Create: " + ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public PartialViewResult Delete(string id) { CategoriesModels model = GetDetail(id); return(PartialView("_Delete", model)); }