コード例 #1
0
 public ActionResult Create(DefaultCurrencyModels model)
 {
     try
     {
         if (string.IsNullOrEmpty(model.Name))
         {
             ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Name field is required"));
             return(View(model));
         }
         string msg    = "";
         bool   result = _factory.InsertOrUpdateDefaultCurrency(model, ref msg);
         if (result)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("Name", msg);
             return(View(model));
         }
     }
     catch (Exception ex)
     {
         _logger.Error("DefaultCurrency_Create: " + ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
コード例 #2
0
 public DefaultCurrencyModels GetDetail(string id)
 {
     try
     {
         DefaultCurrencyModels model = _factory.GetListDefaultCurrency(null, id)[0];
         return(model);
     }
     catch (Exception ex)
     {
         _logger.Error("DefaultCurrency_Detail: " + ex);
         return(null);
     }
 }
コード例 #3
0
        public ActionResult Import(DefaultCurrencyModels model)
        {
            try
            {
                if (model.ListStores == null)
                {
                    ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose store."));
                    return(View(model));
                }
                if (model.ExcelUpload == null || model.ExcelUpload.ContentLength <= 0)
                {
                    ModelState.AddModelError("ExcelUpload", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Excel filename cannot be null"));
                    return(View(model));
                }

                ImportModel    importModel = new ImportModel();
                string         msg         = "";
                StatusResponse response    = _factory.Import(model.ExcelUpload, model.ListStores, ref importModel, ref msg);
                if (!response.Status)
                {
                    ModelState.AddModelError("", response.MsgError);
                    return(View(model));
                }

                // Delete File Excel and File Zip Image
                CommonHelper.DeleteFileFromServer(CommonHelper.GetFilePath(model.ExcelUpload));

                //if (!ModelState.IsValid)
                //    return View(model);

                if (msg.Equals(""))
                {
                    return(View("ImportDetail", importModel));
                }
                else
                {
                    _logger.Error("Currency_Import: " + msg);
                    ModelState.AddModelError("ExcelUpload", msg);
                    return(View(model));
                }
            }
            catch (Exception e)
            {
                _logger.Error(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Currency") + "_" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import") + ": " + e);
                //return new HttpStatusCodeResult(400, e.Message);
                ModelState.AddModelError("ExcelUpload", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import file have error."));
                return(View(model));
            }
        }
コード例 #4
0
        public ActionResult Export(DefaultCurrencyModels model)
        {
            try
            {
                if (model.ListStores == null)
                {
                    ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose store."));
                    return(View(model));
                }

                XLWorkbook wb        = new XLWorkbook();
                var        wsSetMenu = wb.Worksheets.Add("Sheet1");
                Shared.Models.StatusResponse response = _factory.Export(ref wsSetMenu, model.ListStores);

                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("Currency").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("DefaultCurrency_Export: " + e);
                return(new HttpStatusCodeResult(400, e.Message));
            }
        }
コード例 #5
0
        //InsertOrUpdateDefaultCurrency
        public bool InsertOrUpdateDefaultCurrency(DefaultCurrencyModels model, ref string msg)
        {
            try
            {
                DefaultCurrencyApiModels paraBody = new DefaultCurrencyApiModels();
                paraBody.AppKey        = Commons.AppKey;
                paraBody.AppSecret     = Commons.AppSecret;
                paraBody.CreatedUser   = Commons.CreateUser;
                paraBody.RegisterToken = new RegisterTokenModels();
                //-----

                paraBody.StoreId = model.StoreId;
                paraBody.Id      = model.Id;

                paraBody.IsSelected = model.IsSelected;
                paraBody.Name       = model.Name;
                paraBody.Symbol     = model.Symbol;
                //====================
                var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.CreateOrEditCurrency, null, paraBody);
                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)
            {
                _logger.Error("DefaultCurrency_InsertOrUpdate: " + e);
                return(false);
            }
        }
コード例 #6
0
 public ActionResult Delete(DefaultCurrencyModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.DeleteDefaultCurrency(model.Id, ref msg);
         if (!result)
         {
             //ModelState.AddModelError("Name", "Have a error when you delete an Category");
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         _logger.Error("DefaultCurrency_Delete: " + ex);
         ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Have a error when you delete an currency"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
コード例 #7
0
 public ActionResult Edit(DefaultCurrencyModels model)
 {
     try
     {
         if (string.IsNullOrEmpty(model.StoreId))
         {
             ModelState.AddModelError("StoreID", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose store"));
         }
         if (string.IsNullOrEmpty(model.Name))
         {
             ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Default Currency Name is required"));
         }
         if (!ModelState.IsValid)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Edit", model));
         }
         string msg = "";
         //====================
         var result = _factory.InsertOrUpdateDefaultCurrency(model, ref msg);
         if (result)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("Name", msg);
             return(PartialView("_Edit", model));
         }
     }
     catch (Exception ex)
     {
         _logger.Error("DefaultCurrency_Edit: " + ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
コード例 #8
0
        // IMPORT
        public StatusResponse Import(HttpPostedFileBase excelFile, List <string> lstStore, ref ImportModel importModel, ref string msg)
        {
            StatusResponse Response = new StatusResponse();
            DataTable      dt       = new DataTable();

            FileInfo[] lstFileImg = new FileInfo[] { };
            Response = ProcessDataImport(ref dt, excelFile, "SBSettingCurrency.xlsx", out lstFileImg);

            if (!Response.Status)
            {
                msg = Response.MsgError;
                return(Response);
            }

            List <DefaultCurrencyModels> listData = new List <DefaultCurrencyModels>();
            ImportItem itemErr    = null;
            bool       flagInsert = true;
            string     msgError   = "";

            foreach (var item in lstStore)
            {
                foreach (DataRow row in dt.Rows)
                {
                    try
                    {
                        flagInsert = true;
                        msgError   = "";

                        string rowText = "";
                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            rowText += row[i].ToString().Trim();
                        }
                        if (string.IsNullOrEmpty(rowText))
                        {
                            continue;
                        }
                        DefaultCurrencyModels model = new DefaultCurrencyModels();

                        model.Index = row[0].ToString();
                        // 1 - Currency Name
                        model.Name = row[1].ToString().Trim().Replace("  ", " ");
                        // 2 - IsActive
                        model.IsSelected = string.IsNullOrEmpty(row[3].ToString()) ? false :
                                           _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(row[3].ToString()).Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("selected")) ? true : false;
                        // 3 - Symbol
                        model.Symbol  = row[2].ToString().Trim().Equals("") ? "" : row[2].ToString().Trim();
                        model.StoreId = item;

                        if (model.Name.Equals(""))
                        {
                            flagInsert = false;
                            msgError  += _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Name is required");
                        }
                        if (model.Symbol.Equals(""))
                        {
                            flagInsert = false;
                            msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Symbol is required");
                        }
                        if (listData.Any(x => x.Name.Equals(model.Name)))
                        {
                            flagInsert = false;
                            msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Name is exist");
                        }
                        if (flagInsert)
                        {
                            listData.Add(model);
                        }
                        else
                        {
                            itemErr      = new ImportItem();
                            itemErr.Name = model.Name;
                            itemErr.ListFailStoreName.Add("");
                            itemErr.ListErrorMsg.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Row") + ":" + model.Index + msgError);
                            importModel.ListImport.Add(itemErr);
                        }
                    }
                    catch (Exception e)
                    {
                        importModel.ListImport.Add(new ImportItem {
                            Name = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Currency"), ListFailStoreName = lstStore, ListErrorMsg = new List <string> {
                                e.Message
                            }
                        });
                    }
                }
            }
            Response.Status = true;
            //=====================
            //try
            //{
            DefaultCurrencyApiModels paraBody = new DefaultCurrencyApiModels();

            paraBody.AppKey        = Commons.AppKey;
            paraBody.AppSecret     = Commons.AppSecret;
            paraBody.CreatedUser   = Commons.CreateUser;
            paraBody.RegisterToken = new RegisterTokenModels();
            paraBody.ListCurrency  = listData;

            //====================
            var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.ImportCurrency, 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);

                foreach (ImportResult itemError in listError)
                {
                    ImportItem item = new ImportItem();
                    item.Name = itemError.Property;
                    item.ListFailStoreName.Add(itemError.StoreName);
                    item.ListErrorMsg.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Row") + ": " + itemError.Index + "<br/>" + itemError.Error);
                    importModel.ListImport.Add(item);
                }
                if (importModel.ListImport.Count == 0)
                {
                    ImportItem item = new ImportItem();
                    item.Name = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Currency");
                    item.ListSuccessStoreName.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import Currency Successful"));
                    importModel.ListImport.Add(item);
                }
            }
            return(Response);
        }
コード例 #9
0
        public ActionResult Create()
        {
            DefaultCurrencyModels model = new DefaultCurrencyModels();

            return(View(model));
        }
コード例 #10
0
        public new PartialViewResult View(string id)
        {
            DefaultCurrencyModels model = GetDetail(id);

            return(PartialView("_View", model));
        }
コード例 #11
0
        public PartialViewResult Edit(string id)
        {
            DefaultCurrencyModels model = GetDetail(id);

            return(PartialView("_Edit", model));
        }