Exemple #1
0
 public JsonResult CreatePostIt(PostItHelpModel postItHelpModel)
 {
     if (ModelState.IsValid)
     {
         TimeZone localTime = TimeZone.CurrentTimeZone;
         Console.WriteLine(localTime.StandardName);
         using (PostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
             using (CustomerRepository _customerRepository = new CustomerRepository(ApplicationDbContext.Create()))
                 using (EmployeeRepository _employeeRepository = new EmployeeRepository(ApplicationDbContext.Create()))
                 {
                     PostIt postIt = new PostIt()
                     {
                         Title       = postItHelpModel.title,
                         From        = postItHelpModel.start,
                         To          = postItHelpModel.end,
                         Note        = postItHelpModel.note,
                         DayOfWeek   = postItHelpModel.dayOfWeek,
                         TemplateNo  = postItHelpModel.templateNo,
                         CreatedDate = DateTime.Now,
                         CustomerId  = postItHelpModel.customerId,
                         EmployeeId  = postItHelpModel.employeeId,
                         IsAssigned  = true
                     };
                     _postItRepo.Insert(postIt);
                     _postItRepo.Save();
                     return(Json(true));
                 }
     }
     return(Json(false));
 }
Exemple #2
0
 public JsonResult UpdatePostIt(PostItHelpModel postItHelpModel)
 {
     if (ModelState.IsValid)
     {
         using (PostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
             using (CustomerRepository _customerRepository = new CustomerRepository(ApplicationDbContext.Create()))
                 using (EmployeeRepository _employeeRepository = new EmployeeRepository(ApplicationDbContext.Create()))
                 {
                     PostIt postIt = _postItRepo.Find(postItHelpModel.id);
                     postIt.Title      = postItHelpModel.title;
                     postIt.From       = postItHelpModel.start;
                     postIt.To         = postItHelpModel.end;
                     postIt.CustomerId = postItHelpModel.customerId;
                     postIt.EmployeeId = postItHelpModel.employeeId;
                     postIt.DayOfWeek  = postItHelpModel.dayOfWeek;
                     postIt.Note       = postItHelpModel.note;
                     postIt.TemplateNo = postItHelpModel.templateNo;
                     postIt.IsAssigned = true;
                     _postItRepo.Update(postIt);
                     _postItRepo.Save();
                     return(Json(true));
                 }
     }
     return(Json(false));
 }
Exemple #3
0
 public JsonResult DelPostIt(int id)
 {
     using (IPostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
     {
         _postItRepo.Delete(id);
         _postItRepo.Save();
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #4
0
        public JsonResult CreateTemplate(TemplateData templateData)
        {
            IQueryable <PostIt> postIts     = null;
            List <PostIt>       postItsList = new List <PostIt>();

            using (IPostItRepository _postItRepository = new PostItRepository(ApplicationDbContext.Create()))
                using (ICustomerRepository _customerRepository = new CustomerRepository(ApplicationDbContext.Create()))
                    using (IEmployeeRepository _employeeRepository = new EmployeeRepository(ApplicationDbContext.Create()))
                    {
                        postIts = _postItRepository.AllForTemplate(templateData.templateId);

                        foreach (var postIt in postIts)
                        {
                            var from        = Convert.ToDateTime(templateData.start);
                            var fromAddDays = from.AddDays(postIt.DayOfWeek);
                            var to          = Convert.ToDateTime(templateData.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")));

                            PostIt newPostIt = new PostIt()
                            {
                                Title       = postIt.Title,
                                From        = finalStart.ToString("s"),
                                To          = finalEnd.ToString("s"),
                                Note        = postIt.Note,
                                CustomerId  = postIt.CustomerId,
                                EmployeeId  = postIt.EmployeeId,
                                TemplateNo  = 0,
                                TemplateId  = postIt.EventId,
                                CreatedDate = DateTime.Now,
                                DayOfWeek   = postIt.DayOfWeek,
                                IsAssigned  = true
                            };
                            postItsList.Add(newPostIt);
                        }
                        foreach (var postIt in postItsList)
                        {
                            _postItRepository.Insert(postIt);
                            _postItRepository.Save();
                        }
                    }
            return(Json(true));
        }
        public ActionResult Delete(int id)
        {
            using (ICustomerRepository _customerRepo = new CustomerRepository(ApplicationDbContext.Create()))
                using (IPostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
                {
                    var postItsForCus = _postItRepo.AllForCustomer(id).ToList();
                    foreach (var postIt in postItsForCus)
                    {
                        postIt.IsAssigned = false;
                        _postItRepo.Update(postIt);
                        _postItRepo.Save();
                    }

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