public ActionResult IndexExport(int month, int year, string ticketSubject) { try { DateTime startDate = new DateTime(year, month, 1); DateTime endDate = startDate.AddMonths(1).AddSeconds(-1); TicketInfoList list = TicketInfoList.GetReportByDate(startDate, endDate, ticketSubject); var file = CreateFile(list, month, year, ticketSubject); if (file != null) { return(new FileContentResult(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = "My Excel File.xlsx" }); } } catch (Exception ex) { LogActivity log = LogActivity.NewLogActivity(); log.ControllerName = "ExportController"; log.ActionName = "IndexExport"; log.LogData = Newtonsoft.Json.JsonConvert.SerializeObject(ex.StackTrace); log.CreatedBy = User.Identity.Name; log.CreatedDate = DateTime.Now; log = log.Save(); } return(View()); }
public ActionResult Index(ViewModel.Ticket m) { string errorMessage = string.Empty; try { foreach (var item in m.Solution) { if (item.UpdateDate == DateTime.MinValue) { item.UpdateDate = DateTime.Now; } } using (DatabaseManager ctx = new DatabaseManager(true)) { if (string.IsNullOrEmpty(m.TicketNo)) { m.TicketNo = TicketNo.Create(User.Identity.Name, "TICKET"); } Ticket obj = ViewModel.Ticket.ConvertToTicketBusiness(m); obj.Requester = m.Requester.Email; obj.TicketStatus = TicketStatus.Open.ToString(); obj.Escalation = User.Identity.Name; obj.CreatedBy = User.Identity.Name; obj.CreatedDate = DateTime.Now; obj.UpdatedBy = obj.CreatedBy; obj.UpdatedDate = obj.CreatedDate; string updatecommand = "Created";//GetUpdateCommand(m, obj); var objHistory = SaveTicketHistory(obj, updatecommand); if (m.isClosed) { obj.TicketStatus = TicketStatus.Closed.ToString(); objHistory.TicketStatus = TicketStatus.Closed.ToString(); } if (obj.IsValid && objHistory.IsValid) { obj = obj.Save(); objHistory = objHistory.Save(); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var item in obj.GetBrokenRules()) { sb.AppendLine(item.Description); } foreach (var item in objHistory.GetBrokenRules()) { sb.AppendLine(item.Description); } errorMessage = sb.ToString(); } Customer cust = ViewModel.Ticket.ConvertToCustomerBusiness(m.Requester); if (string.IsNullOrEmpty(cust.CreatedBy)) { cust.CreatedBy = User.Identity.Name; cust.CreatedDate = DateTime.Now; } cust.UpdatedBy = User.Identity.Name; cust.UpdatedDate = DateTime.Now; if (cust.IsValid) { cust = cust.Save(); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var item in cust.GetBrokenRules()) { sb.AppendLine(item.Description); } errorMessage = errorMessage + "---" + sb.ToString(); } if (string.IsNullOrEmpty(errorMessage)) { ctx.SaveChanges(); ViewBag.SuccessMsg = "Success"; } else { throw new Exception("Terjadi kesalahan!"); } } } catch (Exception ex) { errorMessage = ex.Message + "---" + errorMessage; ViewBag.ErrorMsg = errorMessage; LogActivity log = LogActivity.NewLogActivity(); log.ControllerName = "Ticketing"; log.ActionName = "Index"; log.LogData = Newtonsoft.Json.JsonConvert.SerializeObject(errorMessage); log.CreatedBy = User.Identity.Name; log.CreatedDate = DateTime.Now; log = log.Save(); return(View(m)); } return(RedirectToAction("IndexInbox", "Inbox")); }