public ActionResult CreateTag(TagCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (viewModel.StartDate > viewModel.EndDate)
                {
                    viewModel.Months = MonthYearHelper.GetMonthList();
                    viewModel.Years  = MonthYearHelper.GetYearList();
                    ModelState.AddModelError("", "End date must not be greater than Start Date");
                    return(View(viewModel));
                }

                //check for overlap
                var overlappedTags = _tagRepository.FirstOrDefault(x => !x.IsDeleted && x.Month == viewModel.Month && x.Year == viewModel.Year &&
                                                                   viewModel.StartDate <= x.EndDate && x.StartDate <= viewModel.EndDate);

                if (overlappedTags != null)
                {
                    viewModel.Months = MonthYearHelper.GetMonthList();
                    viewModel.Years  = MonthYearHelper.GetYearList();
                    ModelState.AddModelError("", "Date must not overlap");
                    return(View(viewModel));
                }

                var tag = viewModel.MapItem <Tag>();
                _tagRepository.Add(tag);
                _unitOfWork.Commit();

                return(RedirectToAction("Tags", new { month = viewModel.Month, year = viewModel.Year }));
            }

            viewModel.Months = MonthYearHelper.GetMonthList();
            viewModel.Years  = MonthYearHelper.GetYearList();
            return(View(viewModel));
        }
示例#2
0
        public ActionResult DataSheet(int month, int year, HttpPostedFileBase file)
        {
            var viewModel = new DataSheetViewModel
            {
                Year    = year,
                Month   = month,
                Years   = MonthYearHelper.GetYearList(),
                Months  = MonthYearHelper.GetMonthList(),
                HasTags = true
            };

            if (file != null && file.ContentLength > 0)
            {
                if (file.FileName.EndsWith(".csv"))
                {
                    using (var stream = file.InputStream)
                    {
                        using (var csvTable = new DataTable())
                        {
                            using (var reader = new CsvReader(new StreamReader(stream), true))
                            {
                                csvTable.Load(reader);

                                if (!csvTable.IsHeaderValid(Common.Constants.Constants.DATASHEET_HEADERS))
                                {
                                    ModelState.AddModelError("", String.Format("Uploaded file does not contain all the required headers: {0}", String.Join(",", Common.Constants.Constants.DATASHEET_HEADERS)));
                                    return(View(viewModel));
                                }

                                try
                                {
                                    _dataSheetService.UploadDataSheet(month, year, csvTable);
                                }
                                catch (Exception ex)
                                {
                                    ModelState.AddModelError("", ex.Message);
                                }
                            }
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid file format. Please select only .csv file");
                }
            }

            //TempData["Message"] = "Datasheet has been successfully uploaded";
            return(View(viewModel));
        }
        public ActionResult CreateTag(int?year = null, int?month = null)
        {
            var now          = DateTime.Now;
            var currentMonth = month ?? now.Month;
            var currentYear  = year ?? now.Year;

            var viewModel = new TagCreateViewModel
            {
                Month  = currentMonth,
                Year   = currentYear,
                Months = MonthYearHelper.GetMonthList(),
                Years  = MonthYearHelper.GetYearList(),
            };

            return(View(viewModel));
        }
        public ActionResult EditTag(int id)
        {
            var tag = _tagRepository.GetById(id);

            if (tag == null)
            {
                return(RedirectToAction("Tags"));
            }

            var viewModel = tag.MapItem <TagCreateViewModel>();

            viewModel.Months       = MonthYearHelper.GetMonthList();
            viewModel.Years        = MonthYearHelper.GetYearList();
            viewModel.HasDataSheet = _dataSheetService.HasDataSheet(tag.Year, tag.Month);
            viewModel.Year         = tag.Year;
            viewModel.Month        = tag.Month;
            return(View(viewModel));
        }
示例#5
0
        public ActionResult DataSheet(int?month = null, int?year = null)
        {
            var now     = DateTime.Now;
            var y       = year ?? now.Year;
            var m       = month ?? now.Month;
            var hasTags = _tagService.HasTags(y, m);

            var viewModel = new DataSheetViewModel
            {
                Year    = y,
                Month   = m,
                HasTags = hasTags,
                Years   = MonthYearHelper.GetYearList(),
                Months  = MonthYearHelper.GetMonthList()
            };

            return(View(viewModel));
        }
示例#6
0
        public ActionResult NewUserMTDDataSheet(int?month = null, int?year = null)
        {
            var now = DateTime.Now;
            var m   = month ?? now.Month;
            var y   = year ?? now.Year;

            var datasheet = _dataSheetService.GetMonthlyNewUserReport(y, m).ToList();
            var viewModel = new NewUserDataSheetViewModel
            {
                Year       = y,
                Month      = m,
                DataSheets = datasheet,
                Years      = MonthYearHelper.GetYearList(),
                Months     = MonthYearHelper.GetMonthList()
            };

            return(View(viewModel));
        }
        public ActionResult WeeklyTagsRun(int?year = null, int?month = null)
        {
            var viewModel = new WeeklyTagRunViewModel
            {
                Month  = month ?? DateTime.Now.Month,
                Year   = year ?? DateTime.Now.Year,
                Months = MonthYearHelper.GetMonthList(),
                Years  = MonthYearHelper.GetYearList()
            };

            var data           = _dataSheetService.GetWeeklyReport(viewModel.Month, viewModel.Year);
            var inhouseSummary = _dataSheetService.GetWeeklyInHouseSummary(viewModel.Month, viewModel.Year);

            viewModel.WeeklyReport         = data;
            viewModel.WeeklyInhouseSummary = inhouseSummary;
            viewModel.Tags = _tagService.GetTags(viewModel.Year, viewModel.Month).OrderBy(x => x.StartDate);

            return(View(viewModel));
        }
        public ActionResult Tags(int?month = null, int?year = null)
        {
            var now          = DateTime.Now;
            var currentMonth = month ?? now.Month;
            var currentYear  = year ?? now.Year;

            var tags = _tagService.GetTags(currentYear, currentMonth);

            var viewModel = new TagListViewModel
            {
                Year   = currentYear,
                Month  = currentMonth,
                Months = MonthYearHelper.GetMonthList(),
                Years  = MonthYearHelper.GetYearList(),
                Tags   = tags
            };

            return(View(viewModel));
        }
示例#9
0
        public ActionResult NewUserMTDDataSheet(int month, int year, HttpPostedFileBase file)
        {
            var viewModel = new NewUserDataSheetViewModel
            {
                Year   = year,
                Month  = month,
                Years  = MonthYearHelper.GetYearList(),
                Months = MonthYearHelper.GetMonthList()
            };

            if (file != null && file.ContentLength > 0)
            {
                if (file.FileName.EndsWith(".csv"))
                {
                    using (var stream = file.InputStream)
                    {
                        using (var csvTable = new DataTable())
                        {
                            using (var reader = new CsvReader(new StreamReader(stream), true))
                            {
                                csvTable.Load(reader);
                                var headers = new List <string> {
                                    "TM CODE", "BRAND", "Date", "FIRST USE"
                                };
                                if (!csvTable.IsHeaderValid(headers))
                                {
                                    ModelState.AddModelError("", String.Format("Uploaded file does not contain all the required headers: {0}", String.Join(",", headers)));
                                    return(View(viewModel));
                                }
                                _dataSheetService.UploadNewUserMTDDataSheet(year, csvTable);
                            }
                        }
                    }
                }
            }

            //TempData["Message"] = "New User MTD Datasheet has been successfully uploaded";
            return(RedirectToAction("NewUserMTDDataSheet", new { month, year }));
        }
        public ActionResult MonthlyTagsRun(int?year = null, string months = null)
        {
            var monthList         = MonthYearHelper.GetMonthList();
            var selectedMonth     = !String.IsNullOrEmpty(months) ? months.Split(',') : new string [0];
            var selectedMonthList = !String.IsNullOrEmpty(months) ? selectedMonth : monthList.Select(x => x.Value);

            var viewModel = new MonthlyTagRunViewModel
            {
                Year           = year ?? DateTime.Now.Year,
                SelectedMonths = selectedMonthList,
                Months         = monthList,
                Years          = MonthYearHelper.GetYearList()
            };

            var onlineList  = new List <MonthlyReportData>();
            var inHouseList = new List <MonthlyReportData>();

            GetMonthlyReportData(viewModel.Year, onlineList, inHouseList);

            viewModel.InhouseMonthlyReport = inHouseList;
            viewModel.OnlineMonthlyReport  = onlineList;
            return(View(viewModel));
        }