Esempio n. 1
0
        public ActionResult QuickAddTimeSheet(CompleteTimeSheetViewModel newTimeSheetViewModel)
        {
            if (ModelState.IsValid)
            {
                var newTimeSheetEntity = mapper.Map <QuickAddTimeSheetViewModel, TimeSheet>(newTimeSheetViewModel.QuickAddTimeSheet);
                newTimeSheetEntity.Date = DateTime.Now;
                var last = dbContext.TimeSheets.OrderByDescending(w => w.TimeSheetID).FirstOrDefault();
                if (last.TimeTo == TimeSpan.Zero)
                {
                    last.TimeTo = newTimeSheetViewModel.QuickAddTimeSheet.TimeFrom;
                }

                var date = newTimeSheetEntity.Date;
                date = DateTime.Now.Date;
                var dateOnly = new DateTime(date.Year, date.Month, date.Day);

                dbContext.TimeSheets.Add(newTimeSheetEntity);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }

            var timeSheetEntity = dbContext.TimeSheets.AsEnumerable().OrderByDescending(w => w.TimeSheetID);

            var timeSheetViewModel = mapper.Map <IEnumerable <TimeSheet>, IEnumerable <TimeSheetViewModel> >(timeSheetEntity);

            newTimeSheetViewModel.TimeSheets = timeSheetViewModel;
            return(View("Index", newTimeSheetViewModel));
        }
Esempio n. 2
0
        public ActionResult AddDailyPlan(AddDailyPlanViewModel newDailyPlanViewModel)
        {
            if (ModelState.IsValid)
            {
                var dailyPlanEntity         = mapper.Map <AddDailyPlanViewModel, DailyPlan>(newDailyPlanViewModel);
                var workItemsDayBefore      = new List <WorkItem>();
                var workItemsToday          = new List <WorkItem>();
                var listDailyPlansBeforeAdd = context.DailyPlans.Select(dp => dp.DailyPlanID);

                foreach (var id in newDailyPlanViewModel.SelectedWorkItemsToday)
                {
                    var workItem = context.WorkItems.Where(x => x.WorkItemID == id).FirstOrDefault();
                    workItemsToday.Add(workItem);
                }

                foreach (var id in newDailyPlanViewModel.SelectedWorkItemsDayBefore)
                {
                    int number = 0;
                    if (int.TryParse(id, out number))
                    {
                        var workItem = context.WorkItems.Where(x => x.WorkItemID == number).FirstOrDefault();
                        workItemsDayBefore.Add(workItem);
                    }
                    if (id.ToString().Length >= 3 && id.ToString().Length <= 100)
                    {
                        var workItem = new WorkItem();
                        workItem.Title       = id.ToString();
                        workItem.Description = "No description at this time";
                        workItem.Status      = Infrastructure.Enums.Status.IN_PROGRESS;
                        workItem.IsEnabled   = true;
                        workItem.IsDeleted   = false;
                        context.WorkItems.Add(workItem);

                        workItemsDayBefore.Add(workItem);
                    }
                }
                dailyPlanEntity.Date      = DateTime.Now;
                dailyPlanEntity.Today     = workItemsToday;
                dailyPlanEntity.DayBefore = workItemsDayBefore;
                context.DailyPlans.Add(dailyPlanEntity);
                context.SaveChanges();

                return(RedirectToAction("Index"));
            }

            newDailyPlanViewModel.Date      = DateTime.Now;
            newDailyPlanViewModel.Today     = FillListWorkItemsToday();
            newDailyPlanViewModel.DayBefore = FillListWorkItemsDayBefore();

            return(View(newDailyPlanViewModel));
        }
        public ActionResult AddProject(AddProjectViewModel newProjectViewModel)
        {
            if (ModelState.IsValid)
            {
                Project newProjectEntity = mapper.Map <AddProjectViewModel, Project>(newProjectViewModel);
                newProjectEntity.IsEnabled = true;
                dbContext.Projects.Add(newProjectEntity);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public ActionResult AddWorkItem(AddWorkItemViewModel newWorkItemViewModel)
        {
            if (ModelState.IsValid)
            {
                WorkItem newWorkItemEntity = mapper.Map <AddWorkItemViewModel, WorkItem>(newWorkItemViewModel);
                newWorkItemEntity.IsEnabled   = true;
                newWorkItemEntity.Description = newWorkItemEntity.Description.Parse();
                dbContext.WorkItems.Add(newWorkItemEntity);
                dbContext.SaveChanges();

                return(RedirectToAction("Index"));
            }

            newWorkItemViewModel.ListOfProjectIDs = getAllProjects();
            return(View(newWorkItemViewModel));
        }