コード例 #1
0
        public new PartialViewResult View(string StoreID, string id)
        {
            SeasonModels model = GetDetail(StoreID, id);

            model.StartDate = model.StartDate.ToLocalTime();
            model.EndDate   = model.EndDate.ToLocalTime();
            return(PartialView("_View", model));
        }
コード例 #2
0
        public SeasonModels GetDetail(string StoreID, string id)
        {
            try
            {
                SeasonModels model = _factory.GetListSeason(StoreID, id)[0];
                if (model.StartTime.Value.Date == Commons._UnlimitedDate.Date || model.EndTime.Value.Date == Commons._UnlimitedDate.Date)
                {
                    model.Unlimited = true;

                    model.TStartTime = TimeSpan.Zero;
                    model.TEndTime   = TimeSpan.Zero;
                }
                else
                {
                    model.StartTime = model.StartTime.Value.ToLocalTime();
                    model.EndTime   = model.EndTime.Value.ToLocalTime();

                    model.TStartTime = model.StartTime.Value.TimeOfDay;
                    model.TEndTime   = model.EndTime.Value.TimeOfDay;
                }


                if (model.RepeatType == (byte)Commons.ERepeatType.DayOfWeek)
                {
                    model.ListWeekDayV2.ForEach(x =>
                    {
                        if (model.ListDay.Contains(x.Index))
                        {
                            x.IsActive = true;
                            x.Status   = 1;
                        }
                    });
                }
                else if (model.RepeatType == (byte)Commons.ERepeatType.DayOfMonth)
                {
                    model.ListMonthDayV2.ForEach(x =>
                    {
                        if (model.ListDay.Contains(x.Index))
                        {
                            x.IsActive = true;
                            x.Status   = 1;
                        }
                    });
                }
                return(model);
            }
            catch (Exception ex)
            {
                _logger.Error("Season_Detail: " + ex);
                return(null);
            }
        }
コード例 #3
0
        public ActionResult Import(SeasonModels 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("File excel 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("Season_Import: " + msg);
                    ModelState.AddModelError("ExcelUpload", msg);
                    return(View(model));
                }
            }
            catch (Exception e)
            {
                _logger.Error("Season_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(SeasonModels model)
        {
            try
            {
                if (model.ListStores == null)
                {
                    ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose store."));
                    return(View(model));
                }

                XLWorkbook wb = new XLWorkbook();
                var        ws = wb.Worksheets.Add("Sheet1");

                StatusResponse response = _factory.Export(ref ws, model.ListStores);

                if (!response.Status)
                {
                    ModelState.AddModelError("", response.MsgError);
                    return(View(model));
                }

                ViewBag.wb = wb;
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Charset         = System.Text.UTF8Encoding.UTF8.WebName;
                Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
                Response.ContentType     = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", CommonHelper.GetExportFileName("Season").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("Season_Export: " + e);
                //return new HttpStatusCodeResult(400, e.Message);
                ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import file have error."));
                return(View(model));
            }
        }
コード例 #5
0
 public ActionResult Delete(SeasonModels model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.DeleteSeason(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("Season_Delete: " + ex);
         ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Have an error when you delete a Season"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
コード例 #6
0
        public bool InsertOrUpdateSeason(SeasonModels model, ref string msg)
        {
            try
            {
                SeasonApiModels paraBody = new SeasonApiModels();

                SeasonModels SeasonDTO = new SeasonModels();
                SeasonDTO.ID   = model.ID;
                SeasonDTO.Name = model.Name;

                SeasonDTO.StartDate = new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day,
                                                   12, 0, 0);

                SeasonDTO.EndDate = new DateTime(model.EndDate.Year, model.EndDate.Month, model.EndDate.Day,
                                                 12, 0, 0);

                if (model.Unlimited)
                {
                    SeasonDTO.StartTime = model.StartTime;
                    SeasonDTO.EndTime   = model.EndTime;
                }
                else
                {
                    SeasonDTO.StartTime = model.StartDate.Add(model.TStartTime);
                    SeasonDTO.EndTime   = model.EndDate.Add(model.TEndTime);
                }

                SeasonDTO.RepeatType = model.RepeatType;
                SeasonDTO.ListDay    = model.ListDay;
                SeasonDTO.Unlimited  = model.Unlimited;
                SeasonDTO.StoreID    = model.StoreID;
                //---========
                paraBody.SeasonDTO = SeasonDTO;

                paraBody.AppKey        = Commons.AppKey;
                paraBody.AppSecret     = Commons.AppSecret;
                paraBody.CreatedUser   = Commons.CreateUser;
                paraBody.RegisterToken = new RegisterTokenModels();
                paraBody.StoreID       = model.StoreID;
                paraBody.ID            = model.ID;

                //====================
                var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.CreateOrEditSeason, null, paraBody);
                if (result != null)
                {
                    if (result.Success)
                    {
                        return(true);
                    }
                    else
                    {
                        msg = result.Message;
                        _logger.Error(result.Message);
                        return(false);
                    }
                }
                else
                {
                    _logger.Error(result);
                    return(false);
                }
            }
            catch (Exception e)
            {
                _logger.Error("Season_InsertOrUpdate: " + e);
                return(false);
            }
        }
コード例 #7
0
        //public bool DeleteSeason(string ID)
        //{
        //    try
        //    {
        //        SeasonApiModels paraBody = new SeasonApiModels();
        //        paraBody.AppKey = Commons.AppKey;
        //        paraBody.AppSecret = Commons.AppSecret;
        //        paraBody.CreatedUser = Commons.CreateUser;
        //        paraBody.RegisterToken = new RegisterTokenModels();

        //        paraBody.ID = ID;

        //        //====================
        //        var result = (ResponseApiModels)ApiResponse.Post<ResponseApiModels>(Commons.DeleteSeason, null, paraBody);
        //        if (result != null)
        //        {
        //            if (result.Success)
        //                return true;
        //            else
        //            {
        //                _logger.Error(result.Message);
        //                return false;
        //            }
        //        }
        //        else
        //        {
        //            _logger.Error(result);
        //            return false;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        _logger.Error("Season_Delete: " + e);
        //        return false;
        //    }
        //}

        // 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, "SBSettingSeason.xlsx", out lstFileImg);

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

            ImportItem itemErr    = null;
            bool       flagInsert = true;
            string     msgError   = "";

            List <SeasonModels> listData = new List <SeasonModels>();

            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;
                        }

                        string   msgItem   = "";
                        DateTime StartDate = DateTimeHelper.GetDateImport(row[2].ToString(), ref msgItem);
                        DateTime EndDate   = DateTimeHelper.GetDateImport(row[3].ToString(), ref msgItem);

                        DateTime StartTime = row[4].ToString().ToLower().Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("unlimited")) ? Commons._MinDate : DateTimeHelper.GetTimeImport(row[4].ToString(), ref msgItem);
                        DateTime EndTime   = row[5].ToString().ToLower().Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("unlimited")) ? Commons._MinDate : DateTimeHelper.GetTimeImport(row[5].ToString(), ref msgItem);

                        if (!msgItem.Equals(""))
                        {
                            flagInsert = false;
                            msgError   = msgItem;
                        }

                        SeasonModels model = new SeasonModels();
                        model.Index = row[0].ToString();
                        // 1 - Discount Name
                        model.Name = row[1].ToString().Trim().Replace("  ", " ");

                        model.StartDate = row[2].ToString().Equals("") ? Commons._ExpiredDate : StartDate;
                        model.EndDate   = row[3].ToString().Equals("") ? Commons._ExpiredDate : EndDate;

                        model.StartTime = StartTime;
                        model.EndTime   = EndTime;

                        model.RepeatType = row[6].ToString().ToLower().Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(Commons.RPT_DayOfWeek.ToLower())) ? (byte)Commons.ERepeatType.DayOfWeek :
                                           row[6].ToString().ToLower().Equals(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(Commons.RPT_DayOfMonth.ToLower())) ? (byte)Commons.ERepeatType.DayOfMonth : 0;

                        List <int> lstDays = new List <int>();
                        if (!string.IsNullOrEmpty(row[7].ToString()))
                        {
                            string[] arrInt = row[7].ToString().Split('-');
                            for (int i = 0; i < arrInt.Length; i++)
                            {
                                if (!string.IsNullOrEmpty(arrInt[i]))
                                {
                                    lstDays.Add(int.Parse(arrInt[i]));
                                }
                            }
                        }
                        model.ListDay = lstDays;
                        model.StoreID = item;

                        if (model.StartDate > model.EndDate)
                        {
                            flagInsert = false;
                            msgItem    = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Start Date must be less than To Date.");
                            msgError  += "<br/>" + msgItem;
                        }
                        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 + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(msgError));
                            importModel.ListImport.Add(itemErr);
                        }
                        //Insert List
                        //listData.Add(model);
                    }
                    catch (Exception e)
                    {
                        importModel.ListImport.Add(new ImportItem {
                            Name = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Season"), ListFailStoreName = lstStore, ListErrorMsg = new List <string> {
                                _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(e.Message)
                            }
                        });
                    }
                }
            }
            Response.Status = true;
            //=====================

            //try
            //{
            SeasonApiModels paraBody = new SeasonApiModels();

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

            //====================
            var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.ImportSeason, 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 (var 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/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(itemError.Error));
                    importModel.ListImport.Add(item);
                }
                if (importModel.ListImport.Count == 0)
                {
                    ImportItem item = new ImportItem();
                    item.Name = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Season");
                    item.ListSuccessStoreName.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Import Season Successful"));
                    importModel.ListImport.Add(item);
                }
            }
            return(Response);
        }
コード例 #8
0
        public ActionResult Create()
        {
            SeasonModels model = new SeasonModels();

            return(View(model));
        }
コード例 #9
0
        public ActionResult Export()
        {
            SeasonModels model = new SeasonModels();

            return(View(model));
        }
コード例 #10
0
        public PartialViewResult Delete(string StoreID, string id)
        {
            SeasonModels model = GetDetail(StoreID, id);

            return(PartialView("_Delete", model));
        }
コード例 #11
0
        public ActionResult Edit(SeasonModels 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("Name field is required"));
                }

                //# Date
                if (model.StartDate > model.EndDate)
                {
                    ModelState.AddModelError("StartDate", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Start Date must be less than To Date."));
                }

                if (model.Unlimited)
                {
                    model.StartTime = Commons._MinDate; // new DateTime(1900, 01, 01, 0, 0, 0);
                    model.EndTime   = Commons._MinDate; //new DateTime(1900, 01, 01, 0, 0, 0);
                }
                else
                {
                    model.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, model.TStartTime.Hours, model.TStartTime.Minutes, model.TStartTime.Days);
                    model.EndTime   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, model.TEndTime.Hours, model.TEndTime.Minutes, model.TEndTime.Days);
                }
                //# Repeat Type
                if (model.RepeatType == (byte)Commons.ERepeatType.DayOfWeek)
                {
                    if (model.ListWeekDayV2.Count(x => x.Status == (byte)Commons.EStatus.Deleted) == 7)
                    {
                        ModelState.AddModelError("RepeatType", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please select days in a week"));
                    }
                    else
                    {
                        model.ListDay = model.ListWeekDayV2.Where(x => x.Status != (byte)Commons.EStatus.Deleted).Select(x => x.Index).ToList();
                    }
                }
                else if (model.RepeatType == (byte)Commons.ERepeatType.DayOfMonth)
                {
                    if (model.ListMonthDayV2.Count(x => x.Status == (byte)Commons.EStatus.Deleted) == 31)
                    {
                        ModelState.AddModelError("RepeatType", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please select days in a month"));
                    }
                    else
                    {
                        model.ListDay = model.ListMonthDayV2.Where(x => x.Status != (byte)Commons.EStatus.Deleted).Select(x => x.Index).ToList();
                    }
                }

                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                //====================
                string msg    = "";
                var    result = _factory.InsertOrUpdateSeason(model, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //return PartialView("_Edit", model);
                    ModelState.AddModelError("Name", msg);
                    return(PartialView("_Edit", model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Season_Edit: " + ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }