コード例 #1
0
        public ActionResult Create()
        {
            InteCategoriesModels model = new InteCategoriesModels();

            model.ProductTypeID    = model.ListProductType.Where(w => w.Text.ToLower().Trim() == Commons.EProductType.Dish.ToString().ToLower().Trim()).Select(s => s.Value).FirstOrDefault();
            model.IsIncludeNetSale = true;
            //model.GetListProductType();
            //var lstStore = (List<SelectListItem>)ViewBag.ListStore;
            //model.ListStore = lstStore;
            var lstStore = (SelectList)ViewBag.StoreID;

            model.ListStore = lstStore.ToList();
            return(View(model));
        }
コード例 #2
0
        public InteCategoriesModels GetDetail(string id, int type = 0)
        {
            string Type = type.ToString();

            try
            {
                InteCategoriesModels model = _factory.GetListCategory(null, id, null, CurrentUser.ListOrganizationId).FirstOrDefault();
                if (model != null)
                {
                    model.ImageURL        = string.IsNullOrEmpty(model.ImageURL) ? Commons.Image100_100 : model.ImageURL;
                    model.ProductTypeName = _productTypeFactory.GetProductTypeName(model.Type);
                    if (model.ListCategoryOnStore != null && model.ListCategoryOnStore.Any())
                    {
                        model.ListCategoryOnStore = model.ListCategoryOnStore.OrderBy(oo => oo.StoreName).ToList();
                    }
                    if (!string.IsNullOrEmpty(model.ParentID) || model.ProductTypeName.ToLower().Equals("dish"))
                    {
                        List <string> LstStore = new List <string>();
                        LstStore.AddRange(model.ListCategoryOnStore.Select(s => s.StoreID).ToList());
                        model.ListCategories = GetSelectListParentCategory(LstStore, Type);

                        // Updated 09222017
                        // No include list cate child of current cate
                        model.lstCateGroup = GetSelectListParentCategorySortForEditCate(LstStore, Type, id, model.ParentID);
                    }
                    model.StoreName = string.Join(", ", model.ListCategoryOnStore.Select(z => z.StoreName).ToList());
                    foreach (var item in model.ListCategoryOnStore)
                    {
                        SelectListItem newItem = new SelectListItem();
                        newItem.Value    = item.StoreID;
                        newItem.Text     = item.StoreName;
                        newItem.Selected = true;
                        model.ListStore.Add(newItem);
                    }
                    return(model);
                }
                else
                {
                    model = new InteCategoriesModels();
                    return(model);
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Categories_Detail: " + ex);
                return(null);
            }
        }
コード例 #3
0
        public ActionResult Export(InteCategoriesModels model)
        {
            try
            {
                if (model.ListStores == null)
                {
                    ModelState.AddModelError("ListStores", CurrentUser.GetLanguageTextFromKey("Please choose store."));
                    return(View(model));
                }

                XLWorkbook wb = new XLWorkbook();
                var        wsCategoryMerchant = wb.Worksheets.Add("Category Merchant");
                var        wsCategoryStore    = wb.Worksheets.Add("Category Store");

                StatusResponse response = _factory.Export(ref wsCategoryMerchant, ref wsCategoryStore, model.ListStores, CurrentUser.ListOrganizationId);
                if (!response.Status)
                {
                    ModelState.AddModelError("", response.MsgError);
                    return(View(model));
                }

                ViewBag.wb = wb;
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Charset         = UTF8Encoding.UTF8.WebName;
                Response.ContentEncoding = UTF8Encoding.UTF8;
                Response.ContentType     = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", CommonHelper.GetExportFileName("Categories").Replace(" ", "_")));

                using (var memoryStream = new System.IO.MemoryStream())
                {
                    wb.SaveAs(memoryStream);
                    memoryStream.WriteTo(HttpContext.Response.OutputStream);
                    memoryStream.Close();
                }
                HttpContext.Response.End();
                return(RedirectToAction("Export"));
            }
            catch (Exception e)
            {
                _logger.Error("Categories_Import: " + e);
                return(new HttpStatusCodeResult(400, e.Message));
            }
        }
コード例 #4
0
ファイル: InteCategoriesFactory.cs プロジェクト: ttcp112/FJ
        //public List<CategoryApplyModels> GetListCategoryForProduct(List<string> ListStoreID = null, string Type = null, List<string> ListOrganizationId = null)
        //{
        //    List<CategoryApplyModels> listData = new List<CategoryApplyModels>();
        //    try
        //    {
        //        CategoriesApiModels paraBody = new CategoriesApiModels();
        //        paraBody.StoreID = ListStoreID[0];
        //        paraBody.Type = int.Parse(Type);
        //        paraBody.isGetChild = true;
        //        var result = (ResponseApiModels)ApiResponse.Post<ResponseApiModels>(Commons.GetCategoryForProduct, null, paraBody);
        //        dynamic data = result.Data;
        //        var lstC = data["ListCategory"];
        //        var lstContent = JsonConvert.SerializeObject(lstC/*result.RawData*/);
        //        listData = JsonConvert.DeserializeObject<List<CategoryApplyModels>>(lstContent);
        //        return listData;
        //    }
        //    catch (Exception e)
        //    {
        //        _logger.Error("Categories_GetList: " + e);
        //        return listData;
        //    }
        //}

        public bool InsertOrUpdateCategories(InteCategoriesModels model, ref string msg)
        {
            try
            {
                InteCategoriesApiModels paraBody = new InteCategoriesApiModels();
                paraBody.AppKey         = Commons.AppKey;
                paraBody.AppSecret      = Commons.AppSecret;
                paraBody.CreatedUser    = Commons.CreateUser;
                paraBody.RegisterToken  = new RegisterTokenModels();
                model.Type              = Convert.ToInt32(model.ProductTypeID);
                paraBody.CategoryDetail = model;
                //====================
                NSLog.Logger.Info("InsertOrUpdateCategories request", paraBody);
                var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.InteCreateOrEditCategories, null, paraBody);
                NSLog.Logger.Info("InsertOrUpdateCategories result", result);
                if (result != null)
                {
                    if (result.Success)
                    {
                        return(true);
                    }
                    else
                    {
                        //_logger.Error(result.Message);
                        msg = result.Message;
                        return(false);
                    }
                }
                else
                {
                    _logger.Error(result);
                    return(false);
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
                NSLog.Logger.Error("InsertOrUpdateCategories error", e);
                //_logger.Error("Categories_InsertOrUpdate: " + e.Message.ToString());
                return(false);
            }
        }
コード例 #5
0
 public ActionResult Delete(InteCategoriesModels 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("Have an error when you delete a Categories"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
コード例 #6
0
ファイル: InteCategoriesFactory.cs プロジェクト: ttcp112/FJ
        public List <SetMenuImportResultItem> Import(string filePath, FileInfo[] listFileInfo, out int totalRowExel, List <string> ListOrgID, ref string msg)
        {
            totalRowExel = 0;
            List <SetMenuImportResultItem> importItems = new List <SetMenuImportResultItem>();

            DataTable dtCategoryMerchant = ReadExcelFile(@filePath, "Category Merchant");
            DataTable dtCategoryStore    = ReadExcelFile(@filePath, "Category Store");

            string    tmpExcelPath          = System.Web.HttpContext.Current.Server.MapPath("~/ImportExportTemplate") + "/SBInventoryCategoryInte.xlsx";
            DataTable dtCategoryMerchantTmp = ReadExcelFile(@tmpExcelPath, "Category Merchant");
            DataTable dtCategoryStoreTmp    = ReadExcelFile(@tmpExcelPath, "Category Store");

            if (dtCategoryMerchant.Columns.Count != dtCategoryMerchantTmp.Columns.Count)
            {
                msg = Commons._MsgDoesNotMatchFileExcel;
                return(importItems);
            }
            if (dtCategoryStore.Columns.Count != dtCategoryStoreTmp.Columns.Count)
            {
                msg = Commons._MsgDoesNotMatchFileExcel;
                return(importItems);
            }
            List <InteCategoriesModels> listData = new List <InteCategoriesModels>();
            SetMenuImportResultItem     itemErr  = null;
            bool   flagInsert = true;
            string msgError   = "";

            foreach (DataRow item in dtCategoryMerchant.Rows)
            {
                flagInsert = true;
                msgError   = "";

                if (item[0].ToString().Equals(""))
                {
                    continue;
                }
                int    index    = int.Parse(item[0].ToString());
                string ImageUrl = "";
                if (!string.IsNullOrEmpty(item[8].ToString()))
                {
                    FileInfo file = listFileInfo.FirstOrDefault(m => m.Name.ToLower() == item[8].ToString().ToLower());
                    if (file != null)
                    {
                        if (file.Length > Commons._MaxSizeFileUploadImg)
                        {
                            flagInsert = false;
                            msgError   = Commons._MsgAllowedSizeImg + "<br/>";
                        }
                        else
                        {
                            ImageUrl = Guid.NewGuid() + file.Extension;
                            byte[] photoByte = null;
                            photoByte = System.IO.File.ReadAllBytes(file.FullName);
                            //19/01/2018
                            //photoByte = file.ReadFully();
                            if (!string.IsNullOrEmpty(ImageUrl) && photoByte != null)
                            {
                                var          originalDirectory = new DirectoryInfo(string.Format("{0}Uploads\\", System.Web.HttpContext.Current.Server.MapPath(@"\")));
                                var          path = string.Format("{0}{1}", originalDirectory, 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, ImageUrl, ref photoByte);
                                FTP.Upload(ImageUrl, photoByte);
                                ImageHelper.Me.TryDeleteImageUpdated(path);
                            }
                        }
                    }
                }

                List <CategoryOnStoreWebDTO> ListCategoryOnStore = new List <CategoryOnStoreWebDTO>();
                DataRow[] CategoryOnStoreRow = dtCategoryStore.Select("[" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Merchant Index") + "] = " + index + "");
                foreach (DataRow gCategoryOnStoreRow in CategoryOnStoreRow)
                {
                    if (gCategoryOnStoreRow[0].ToString().Equals(""))
                    {
                        continue;
                    }

                    int ModifierMerchantIndex             = int.Parse(gCategoryOnStoreRow[0].ToString());
                    CategoryOnStoreWebDTO itemCateOnStore = new CategoryOnStoreWebDTO()
                    {
                        OffSet    = int.Parse(gCategoryOnStoreRow[1].ToString()),
                        StoreName = gCategoryOnStoreRow[2].ToString(),
                        Sequence  = string.IsNullOrEmpty(gCategoryOnStoreRow[3].ToString()) ? 1 : int.Parse(gCategoryOnStoreRow[3].ToString()),


                        IsShowInReservation = string.IsNullOrEmpty(gCategoryOnStoreRow[4].ToString()) ? true
                        : bool.Parse(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(gCategoryOnStoreRow[4].ToString()).Equals(
                                         _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Yes")).ToString()) ? true : false,

                        IsShowInKiosk = string.IsNullOrEmpty(gCategoryOnStoreRow[5].ToString()) ? true
                        : bool.Parse(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(gCategoryOnStoreRow[5].ToString()).Equals(
                                         _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Yes")).ToString()) ? true : false,
                    };

                    //Validation
                    if (string.IsNullOrEmpty(gCategoryOnStoreRow[0].ToString()))
                    {
                        flagInsert = false;
                        msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Merchant Index is required");
                    }
                    if (string.IsNullOrEmpty(gCategoryOnStoreRow[1].ToString()))
                    {
                        flagInsert = false;
                        msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Store Index is required");
                    }
                    if (string.IsNullOrEmpty(itemCateOnStore.StoreName))
                    {
                        flagInsert = false;
                        msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Store Name is required");
                    }
                    if (itemCateOnStore.Sequence < 0)
                    {
                        flagInsert = false;
                        msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please enter a value Sequence larger or equal to 0");
                    }
                    if (ListCategoryOnStore.Count > 0)
                    {
                        var IsExist = ListCategoryOnStore.Exists(x => x.OffSet.Equals(itemCateOnStore.OffSet));
                        if (IsExist)
                        {
                            flagInsert = false;
                            msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Store Index is exist");
                        }
                    }
                    if (flagInsert)
                    {
                        ListCategoryOnStore.Add(itemCateOnStore);
                    }
                }
                //========
                string type  = item[2].ToString().ToLower();
                int    iType = 0;
                if (type.Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(Commons.EProductType.Dish.ToString().ToLower())))
                {
                    iType = (byte)Commons.EProductType.Dish;
                }
                else if (type.Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(Commons.EProductType.Modifier.ToString().ToLower())))
                {
                    iType = (byte)Commons.EProductType.Modifier;
                }
                else if (type.Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(Commons.EProductType.SetMenu.ToString().ToLower())) ||
                         type.Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Set").ToLower()))
                {
                    iType = (byte)Commons.EProductType.SetMenu;
                }

                string ParentName = item[3].ToString();
                if (iType != (byte)Commons.EProductType.Dish)
                {
                    ParentName = "";
                }

                InteCategoriesModels model = new InteCategoriesModels
                {
                    Index      = index.ToString(),
                    Name       = item[1].ToString(),
                    Type       = iType,
                    ParentName = ParentName,

                    GLAccountCode = item[4].ToString(),

                    IsGiftCard = string.IsNullOrEmpty(item[5].ToString()) ? false
                        : bool.Parse(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(item[5].ToString()).Equals(
                                         _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Yes")).ToString()) ? true : false,

                    IsIncludeNetSale = string.IsNullOrEmpty(item[6].ToString()) ? false
                        : bool.Parse(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(item[6].ToString()).Equals(
                                         _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Yes")).ToString()) ? true : false,

                    Description         = item[7].ToString(),
                    ImageURL            = ImageUrl,
                    ListCategoryOnStore = ListCategoryOnStore
                };
                //============
                if (string.IsNullOrEmpty(model.Index))
                {
                    flagInsert = false;
                    msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Merchant Index is required");
                }
                if (string.IsNullOrEmpty(model.Name))
                {
                    flagInsert = false;
                    msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Name is required");
                }
                if (listData.Count > 0)
                {
                    var IsExist = listData.Exists(x => x.Index.Equals(model.Index));
                    if (IsExist)
                    {
                        flagInsert = false;
                        msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Category Merchant Index is exist");
                    }
                }
                //==========
                if (flagInsert)
                {
                    listData.Add(model);
                }
                else
                {
                    SetMenuErrorItem itemerr = new SetMenuErrorItem();
                    itemerr.GroupName    = model.Index;
                    itemerr.ErrorMessage = "Row:" + index + msgError;
                    itemErr      = new SetMenuImportResultItem();
                    itemErr.Name = model.Name;
                    itemErr.ListFailStoreName.Add("");
                    itemErr.ErrorItems.Add(itemerr);
                    importItems.Add(itemErr);
                }
            }

            InteCategoriesApiModels paraBody = new InteCategoriesApiModels();

            paraBody.CreatedUser  = Commons.CreateUser;
            paraBody.ListOrgID    = ListOrgID;
            paraBody.ListCategory = listData;
            paraBody.AppKey       = Commons.AppKey;
            paraBody.AppSecret    = Commons.AppSecret;
            //====================
            var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.InteImportCategories, null, paraBody);

            if (result != null)
            {
                dynamic data       = result.Data;
                var     lstC       = data["ListProperty"];
                var     lstContent = JsonConvert.SerializeObject(lstC);
                var     listError  = JsonConvert.DeserializeObject <List <ImportResult> >(lstContent);

                SetMenuImportResultItem importItem = new SetMenuImportResultItem();
                //importItem.Name = "<strong style=\"color: #d9534f;\">" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Have been") + " [" + (listData.Count - listError.Count) + "] " + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("row(s) import Successful") + "<strong>";
                importItem.Name = "<strong style=\"color: #d9534f;\">" + "[" + (listData.Count - listError.Count) + "]" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(" row(s) have been imported successful") + "<strong>";
                importItems.Insert(0, importItem);

                foreach (ImportResult itemError in listError)
                {
                    SetMenuErrorItem item = new SetMenuErrorItem();
                    item.GroupName    = itemError.Index;
                    item.ErrorMessage = "Row: " + itemError.Index + "<br/>" + itemError.Error;

                    importItem      = new SetMenuImportResultItem();
                    importItem.Name = itemError.Property;
                    importItem.ListFailStoreName.Add(itemError.StoreName);
                    importItem.ErrorItems.Add(item);
                    importItems.Add(importItem);
                }

                if (importItems.Count == 0)
                {
                    importItem      = new SetMenuImportResultItem();
                    importItem.Name = "Category";
                    importItem.ListSuccessStoreName.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import Category Successful"));
                    importItems.Add(importItem);
                }

                //=====
                //importItem = new SetMenuImportResultItem();
                ////importItem.Name = "<strong style=\"color: #d9534f;\">[" + (importItems.Count) + "] rows import successfully<strong>";
                //importItem.Name = "<strong style=\"color: #d9534f;\">[" + (importItems.Count)
                //    + "] " + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("rows import successfully") + "<strong>";
                //importItems.Insert(0, importItem);
                //=====End
            }
            return(importItems);
        }
コード例 #7
0
        public ActionResult Create(InteCategoriesModels model)
        {
            try
            {
                byte[] photoByte       = null;
                var    countStoreFalse = model.ListStore.Where(ww => ww.Selected == true).Count();
                if (countStoreFalse == 0)
                {
                    ModelState.AddModelError("ListStore", CurrentUser.GetLanguageTextFromKey("Please choose store"));
                }

                if (countStoreFalse > 0)
                {
                    List <string> LstStore = new List <string>();
                    if (model.ProductTypeID == Commons.EProductType.Dish.ToString("d"))
                    {
                        LstStore = model.ListStore.Where(w => w.Selected == true).Select(s => s.Value).ToList();
                        //model.ListCategories = GetSelectListParentCategory(LstStore, model.ProductTypeID);
                    }
                }

                if (model.ParentID != null)
                {
                    var parentName = model.ListProductType.Find(x => x.Value.Equals(model.ProductTypeID)).Text.ToLower();
                    if (!parentName.Equals("dish"))
                    {
                        model.ParentID = null;
                    }
                }
                if (string.IsNullOrEmpty(model.Name))
                {
                    ModelState.AddModelError("Name", CurrentUser.GetLanguageTextFromKey("Name field is required"));
                }

                if (model.ListItemOnStores != null && model.ListItemOnStores.Count > 0)
                {
                    model.ListItemOnStores = model.ListItemOnStores.Where(o => o.State == 0).ToList();
                    if (model.ListItemOnStores != null && model.ListItemOnStores.Count > 0)
                    {
                        for (int i = 0; i < model.ListItemOnStores.Count; i++)
                        {
                            if (Convert.ToInt32(model.ListItemOnStores[i].Sequence) < 0)
                            {
                                ModelState.AddModelError(string.Format("ListItemOnStores[{0}].Sequence", model.ListItemOnStores[i].OffSet), CurrentUser.GetLanguageTextFromKey("Limit must be more than 0"));
                            }
                        }
                    }
                }

                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)
                {
                    model.ListItemOnStores = model.ListItemOnStores.Where(o => o.State == 0).ToList();
                    List <string> LstStore = new List <string>();
                    LstStore = model.ListItemOnStores.Select(o => o.StoreID).ToList();
                    if (model.ListItemOnStores.Count > 0)
                    {
                        model.ListCategories = GetSelectListParentCategory(LstStore, model.ProductTypeID);

                        // Updated 09222017
                        model.lstCateGroup = GetSelectListParentCategorySort(LstStore, model.ProductTypeID, model.ParentID);
                    }
                    if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0)
                    {
                        model.ImageURL = "";
                    }

                    var lstStore = (SelectList)ViewBag.StoreID;
                    model.ListStore = lstStore.ToList();

                    return(View(model));
                }
                if (model.ListItemOnStores != null && model.ListItemOnStores.Count > 0)
                {
                    model.ListItemOnStores = model.ListItemOnStores.Where(o => o.State == 0).ToList();
                    foreach (var item in model.ListItemOnStores)
                    {
                        CategoryOnStoreWebDTO newItemOnStore = new CategoryOnStoreWebDTO();
                        newItemOnStore.StoreID             = item.StoreID;
                        newItemOnStore.StoreName           = item.StoreName;
                        newItemOnStore.IsShowInKiosk       = item.IsShowInKiosk;
                        newItemOnStore.IsShowInReservation = item.IsShowInReservation;
                        newItemOnStore.Sequence            = item.Sequence;
                        model.ListCategoryOnStore.Add(newItemOnStore);
                    }
                }

                //====================
                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 09222017
                    List <string> LstStore = model.ListItemOnStores.Select(o => o.StoreID).ToList();
                    model.lstCateGroup = GetSelectListParentCategorySort(LstStore, model.ProductTypeID, model.ParentID);

                    var lstStore = (SelectList)ViewBag.StoreID;
                    model.ListStore = lstStore.ToList();

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Categories_Create: " + ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
コード例 #8
0
        public ActionResult Export()
        {
            InteCategoriesModels model = new InteCategoriesModels();

            return(View(model));
        }
コード例 #9
0
        public PartialViewResult Delete(string id)
        {
            InteCategoriesModels model = GetDetail(id);

            return(PartialView("_Delete", model));
        }
コード例 #10
0
        public ActionResult Edit(InteCategoriesModels model)
        {
            model.ProductTypeID = model.Type.ToString();
            try
            {
                byte[] photoByte = null;
                if (string.IsNullOrEmpty(model.Name))
                {
                    ModelState.AddModelError("Name", CurrentUser.GetLanguageTextFromKey("Name field is required"));
                }

                if (model.ListItemOnStores != null && model.ListItemOnStores.Count > 0)
                {
                    model.ListItemOnStores = model.ListItemOnStores.Where(o => o.State == 0).ToList();
                    if (model.ListItemOnStores != null && model.ListItemOnStores.Count > 0)
                    {
                        for (int i = 0; i < model.ListItemOnStores.Count; i++)
                        {
                            if (Convert.ToInt32(model.ListItemOnStores[i].Sequence) < 0)
                            {
                                ModelState.AddModelError(string.Format("ListItemOnStores[{0}].Sequence", model.ListItemOnStores[i].OffSet), CurrentUser.GetLanguageTextFromKey("Limit must be more than 0"));
                            }
                        }
                    }
                }

                if (string.IsNullOrEmpty(model.ImageURL))
                {
                    model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, "");
                }
                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
                {
                    model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, "");
                }

                // Updated 09222017
                string cateIdChoose = null;
                if (!string.IsNullOrEmpty(model.ParentID))
                {
                    cateIdChoose = model.ParentID;
                }

                if (!ModelState.IsValid)
                {
                    List <string> LstStore = new List <string>();
                    LstStore = model.ListItemOnStores.Select(o => o.StoreID).ToList();
                    List <string> LstStore1 = new List <string>();
                    LstStore1 = model.ListItemOnStores.Where(o => o.IsCheckDisabled == 0).Select(o => o.StoreID).ToList();
                    if (LstStore1.Count > 0 && LstStore1 != null)
                    {
                        for (int i = 0; i < LstStore1.Count; i++)
                        {
                            var IsCheck = model.ListStore.Where(o => o.Value == LstStore1[i]).FirstOrDefault();
                            if (IsCheck != null)
                            {
                                for (int j = 0; j < model.ListStore.Count; j++)
                                {
                                    if (model.ListStore[j].Value == LstStore1[i])
                                    {
                                        model.ListStore[j].Selected = true;
                                    }
                                }
                            }
                        }
                    }
                    if ((ModelState["PictureUpload"]) != null && (ModelState["PictureUpload"]).Errors.Count > 0)
                    {
                        model.ImageURL = "";
                    }
                    model.ListCategories = GetSelectListParentCategory(LstStore, model.ProductTypeID);

                    // Updated 09222017
                    // No include list cate child of current cate
                    model.lstCateGroup = GetSelectListParentCategorySortForEditCate(LstStore, model.ProductTypeID.ToString(), model.ID, model.ParentID);

                    //model = GetDetail(model.ID);
                    //model.GetListProductType();
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                if (model.ListItemOnStores != null && model.ListItemOnStores.Count > 0)
                {
                    model.ListItemOnStores = model.ListItemOnStores.Where(o => o.State == 0).ToList();
                    foreach (var item in model.ListItemOnStores)
                    {
                        CategoryOnStoreWebDTO newItemOnStore = new CategoryOnStoreWebDTO();
                        newItemOnStore.StoreID             = item.StoreID;
                        newItemOnStore.StoreName           = item.StoreName;
                        newItemOnStore.IsShowInKiosk       = item.IsShowInKiosk;
                        newItemOnStore.IsShowInReservation = item.IsShowInReservation;
                        newItemOnStore.Sequence            = item.Sequence;
                        model.ListCategoryOnStore.Add(newItemOnStore);
                    }
                }
                //====================
                string msg = "";
                var    tmp = model.PictureByte;
                model.PictureByte = null;
                var 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);

                    model = GetDetail(model.ID);
                    model.GetListProductType();

                    // Updated 09222017
                    List <string> LstStore = model.ListItemOnStores.Select(o => o.StoreID).ToList();
                    model.lstCateGroup = GetSelectListParentCategorySortForEditCate(LstStore, model.ProductTypeID.ToString(), model.ID, model.ParentID);
                    if (!string.IsNullOrEmpty(cateIdChoose))
                    {
                        var cateChoose = model.lstCateGroup.Where(w => w.Id == cateIdChoose).FirstOrDefault();
                        if (cateChoose != null)
                        {
                            cateChoose.Selected = true;
                        }

                        var currentCate = model.lstCateGroup.Where(w => w.Id == model.ParentID).FirstOrDefault();
                        if (currentCate != null)
                        {
                            currentCate.Selected = false;
                        }
                    }

                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Categories_Edit: " + ex);
                model = GetDetail(model.ID);
                model.GetListProductType();

                // Updated 09222017
                // No include list cate child of current cate
                List <string> LstStore = model.ListItemOnStores.Select(o => o.StoreID).ToList();
                model.lstCateGroup = GetSelectListParentCategorySortForEditCate(LstStore, model.ProductTypeID.ToString(), model.ID, model.ParentID);

                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
コード例 #11
0
        public PartialViewResult Edit(string id, int type)
        {
            InteCategoriesModels model = GetDetail(id, type);
            // var ListAcc = new List<SelectListItem>();
            var ListAcc = new List <XeroDTO>();

            if (model.ListCategories != null && model.ListCategories.Count > 0)
            {
                model.ListCategories = model.ListCategories.Where(o => o.Text != model.Name).ToList();
            }
            model.ProductTypeID = model.Type.ToString();
            if (model.ListCategoryOnStore != null && model.ListCategoryOnStore.Count > 0)
            {
                for (int i = 0; i < model.ListCategoryOnStore.Count; i++)
                {
                    model.ListItemOnStores.Add(new ItemOnStore()
                    {
                        StoreID             = model.ListCategoryOnStore[i].StoreID,
                        StoreName           = model.ListCategoryOnStore[i].StoreName,
                        IsShowInKiosk       = model.ListCategoryOnStore[i].IsShowInKiosk,
                        IsShowInReservation = model.ListCategoryOnStore[i].IsShowInReservation,
                        Sequence            = model.ListCategoryOnStore[i].Sequence,
                        OffSet          = i,
                        State           = 0,
                        IsCheckDisabled = 9
                    });
                }
                //model.ListStore = ViewBag.ListStore;
                var lstStore = (SelectList)ViewBag.StoreID;
                model.ListStore = lstStore.ToList();

                for (int i = 0; i < model.ListStore.Count; i++)
                {
                    var IsCheck = model.ListItemOnStores.Where(o => o.StoreID == model.ListStore[i].Value).FirstOrDefault();
                    if (IsCheck != null)
                    {
                        model.ListStore[i].Selected = true;
                        model.ListStore[i].Disabled = true;
                    }

                    /* get list account xero */
                    //if (Commons.isIntegrateXero)
                    {
                        var InfoStore = CurrentUser.listStore.Where(o => o.ID.Equals(model.ListStore[i].Value)).FirstOrDefault();
                        if (InfoStore != null)
                        {
                            var InfoXero = InfoStore.ThirdParty;
                            if (InfoXero != null)
                            {
                                if (!string.IsNullOrEmpty(InfoXero.ApiURL))
                                {
                                    var data = _facXero.GetListXeroSetting(InfoXero.IPAddress, InfoXero.ThirdPartyID, InfoXero.ApiURL, null);
                                    if (data != null)
                                    {
                                        //var dataJson = data.Select(o => new SelectListItem
                                        //{
                                        //    Value = o.AccountID,
                                        //    Text = o.Name
                                        //}).ToList();
                                        //ListAcc.AddRange(dataJson);
                                        ListAcc.AddRange(data);
                                    }
                                }
                            }
                        }
                        ListAcc = ListAcc.GroupBy(o => o.AccountID)
                                  .Select(o => new XeroDTO
                        {
                            AccountID           = o != null ? o.FirstOrDefault().AccountID : "",
                            Name                = o != null ? o.FirstOrDefault().Name : "",
                            Code                = o != null ? o.FirstOrDefault().Code : "",
                            ReportingCodeName   = o != null ? o.FirstOrDefault().ReportingCodeName : "",
                            NameDisplayCombobox = o != null ? o.FirstOrDefault().Code + "-" + o.FirstOrDefault().Name : "",
                        }).OrderBy(o => o.ReportingCodeName).ToList();

                        //ListAcc = ListAcc.GroupBy(o => new { Value = o.Value, Text = o.Text }).Select(o => new SelectListItem
                        //{
                        //    Value = o.Key.Value,
                        //    Text = o.Key.Text
                        //}).ToList();
                    }
                }
            }
            else
            {
                //model.ListStore = ViewBag.ListStore;
                var lstStore = (SelectList)ViewBag.StoreID;
                model.ListStore = lstStore.ToList();
            }
            ListAcc = ListAcc.OrderBy(o => o.ReportingCodeName).ToList();
            ViewBag.ListAccountXero = new SelectList(ListAcc, "Code", "NameDisplayCombobox", "ReportingCodeName", 1);
            //model.GetListProductType();
            return(PartialView("_Edit", model));
        }