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