Beispiel #1
0
        public JsonResult GetTemplate(string start, string end, int id, int employeeId)
        {
            var calFrom = string.Format("YYYY-MM-DD HH:mm", start);
            var calTo   = string.Format("YYYY-MM-DD HH:mm", end);
            IQueryable <PostIt>    postIts     = null;
            List <PostItHelpModel> postItsList = new List <PostItHelpModel>();

            using (IPostItRepository _postItRepository = new PostItRepository(ApplicationDbContext.Create()))
                using (ICustomerRepository _customerRepository = new CustomerRepository(ApplicationDbContext.Create()))
                    using (IEmployeeRepository _employeeRepository = new EmployeeRepository(ApplicationDbContext.Create()))
                    {
                        if (employeeId > -1)
                        {
                            postIts = _postItRepository.AllForEmployee(employeeId, id);
                        }
                        else
                        {
                            postIts = _postItRepository.AllForTemplate(id);
                        }

                        foreach (var postIt in postIts)
                        {
                            var customer = _customerRepository.Find(postIt.CustomerId);
                            var employee = _employeeRepository.Find(postIt.EmployeeId);

                            var from        = Convert.ToDateTime(start);
                            var fromAddDays = from.AddDays(postIt.DayOfWeek);
                            var to          = Convert.ToDateTime(start);
                            var toAddDays   = to.AddDays(postIt.DayOfWeek);
                            var fromToDate  = DateTime.Parse(postIt.From);
                            var toToDate    = DateTime.Parse(postIt.To);
                            var finalStart  = fromAddDays.Add(TimeSpan.Parse(fromToDate.ToString("HH:mm")));
                            var finalEnd    = toAddDays.Add(TimeSpan.Parse(toToDate.ToString("HH:mm")));

                            PostItHelpModel newPostIt = new PostItHelpModel()
                            {
                                id           = postIt.EventId,
                                title        = postIt.Title,
                                start        = finalStart.ToString("s"),
                                end          = finalEnd.ToString("s"),
                                note         = postIt.Note,
                                customerId   = postIt.CustomerId,
                                employeeId   = postIt.EmployeeId,
                                customerName = customer.Company,
                                employeeName = employee.Name,
                                templateNo   = id,
                                templateId   = null,
                                allDay       = false,
                                dayOfWeek    = postIt.DayOfWeek,
                                isAssigned   = postIt.IsAssigned
                            };
                            postItsList.Add(newPostIt);
                        }
                    }
            var rows = postItsList.ToArray();

            return(Json(rows, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public JsonResult GetPostIts(string start, string end, int id, int employeeId)
        {
            var from = string.Format("YYYY-MM-DD HH:mm", start);
            var to   = string.Format("YYYY-MM-DD HH:mm", end);
            IQueryable <PostIt>    postIts          = null;
            List <PostItHelpModel> postItHelpModels = new List <PostItHelpModel>();

            using (IPostItRepository _postItRepository = new PostItRepository(ApplicationDbContext.Create()))
                using (ICustomerRepository _customerRepository = new CustomerRepository(ApplicationDbContext.Create()))
                    using (IEmployeeRepository _employeeRepository = new EmployeeRepository(ApplicationDbContext.Create()))
                    {
                        if (employeeId > -1)
                        {
                            postIts = _postItRepository.AllForEmployee(from, to, employeeId, id);
                        }
                        else
                        {
                            postIts = _postItRepository.AllForTemplate(from, to, id);
                        }

                        foreach (var postIt in postIts)
                        {
                            var customer = _customerRepository.Find(postIt.CustomerId);
                            var employee = _employeeRepository.Find(postIt.EmployeeId);

                            var employeeName = "";
                            if (employee != null)
                            {
                                employeeName = employee.Name;
                            }

                            var postItHelpModel = new PostItHelpModel()
                            {
                                id           = postIt.EventId,
                                title        = postIt.Title,
                                start        = postIt.From,
                                end          = postIt.To,
                                note         = postIt.Note,
                                customerId   = postIt.CustomerId,
                                employeeId   = postIt.EmployeeId,
                                customerName = customer.Company,
                                employeeName = employeeName,
                                allDay       = false,
                                isAssigned   = postIt.IsAssigned,
                                templateNo   = postIt.TemplateNo,
                                templateId   = postIt.TemplateId
                            };
                            postItHelpModels.Add(postItHelpModel);
                        }
                    }
            var rows = postItHelpModels.ToArray();

            return(Json(rows, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult Delete(int id)
        {
            using (IEmployeeRepository _employeeRepo = new EmployeeRepository(ApplicationDbContext.Create()))
                using (IPostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
                {
                    var postItsForEmployee = _postItRepo.AllForEmployee(id).ToList();
                    foreach (var postIt in postItsForEmployee)
                    {
                        postIt.IsAssigned = false;
                        _postItRepo.Update(postIt);
                        _postItRepo.Save();
                    }

                    _employeeRepo.Delete(id);
                    _employeeRepo.Save();
                    return(RedirectToAction("Index"));
                }
        }