public ActionResult Edit(WorkDoneAttachmentView workDoneAttachmentView, IEnumerable <HttpPostedFileBase> files) { if (ModelState.IsValid) { string sessionToken = Audit.GenerateNewSessionToken(); int workDoneFK = (int)workDoneAttachmentView.WorkDoneFK; foreach (var file in files) { if (file != null && file.ContentLength > 0) { // save attachment to local drive string originalFileName = Path.GetFileName(file.FileName); string fileExtension = Path.GetExtension(originalFileName); string newFileName = System.Guid.NewGuid().ToString(); var path = Path.Combine(Path.GetDirectoryName(Server.MapPath("~")) + "\\Attachments", newFileName + fileExtension); file.SaveAs(path); // save attachment to database IAttachmentsRepository attachmentsRepository = new AttachmentsRepository(db); Attachment attachment = new Attachment(); attachment.Name = originalFileName; attachment.Filename = newFileName; attachment.Extension = fileExtension; attachment.ContentType = "text/plain"; attachmentsRepository.Add(attachment); attachmentsRepository.SaveChanges(sessionToken); int attachmentFK = attachment.AttachmentPK; // save attachment to work done attachments IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneAttachment workDoneAttachment = new WorkDoneAttachment(); workDoneAttachment.AttachmentFK = attachmentFK; workDoneAttachment.WorkDoneFK = workDoneFK; workDoneAttachmentsRepository.Add(workDoneAttachment); workDoneAttachmentsRepository.SaveChanges(sessionToken); } } return(RedirectToAction("Index", "WorkDoneAttachment")); } else { //WorkDones ddl IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); workDoneAttachmentView.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("Description ASC").ToList(), "WorkDonePK", "Description"); return(View(workDoneAttachmentView)); } }
public ActionResult Index() { IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); IAttachmentsRepository attachmentsRepository = new AttachmentsRepository(db); IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); int page = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1; int pageSize = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]); string sortOrder = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "WorkDoneAttachmentPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <WorkDoneAttachmentView> workDoneAttachments = WorkDoneAttachmentView.GetWorkDoneAttachmentView(workDoneAttachmentsRepository.GetValid(), attachmentsRepository.GetValid(), workDonesRepository.GetValid()) .OrderBy(ordering); //WorkDones ddl ViewBag.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("comment").ToList(), "WorkDonePK", "Description", Request.QueryString["workDoneFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); workDoneAttachments = workDoneAttachments.Where(c => c.AttachmentName.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["workDoneFK"])) { int workDoneFK = Convert.ToInt32(Request.QueryString["workDoneFK"]); workDoneAttachments = workDoneAttachments.Where(c => c.WorkDoneFK == workDoneFK); } workDoneAttachments = workDoneAttachments.Page(page, pageSize); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); ViewData["numberOfRecords"] = workDoneAttachments.Where(c => c.AttachmentName.Contains(searchString)).Count(); } else { ViewData["numberOfRecords"] = workDoneAttachments.Count(); } int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("WorkDoneAttachment?" + url + "page=" + numberOfPages)); } else { return(View("Index", workDoneAttachments.ToList())); } }
public ActionResult Edit(int?workDonePK) { if (workDonePK != null) { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); WorkDone workDone = workDonesRepository.GetWorkDoneByPK((int)workDonePK); WorkDoneView workDoneView = new WorkDoneView(); workDoneView.ConvertFrom(workDone, workDoneView); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); IAttachmentsRepository attachmentsRepository = new AttachmentsRepository(db); IQueryable <WorkDoneAttachmentView> workDoneAttachments = WorkDoneAttachmentView.GetWorkDoneAttachmentView(workDoneAttachmentsRepository.GetValid(), attachmentsRepository.GetValid(), workDonesRepository.GetValid()) .Where(c => c.WorkDoneFK == workDonePK).OrderBy("WorkDoneAttachmentPK DESC"); ViewBag.Attachments = workDoneAttachments.ToList(); //to do list ddl IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); workDoneView.ToDoLists = new SelectList(toDoListsRepository.GetValid().ToList(), "ToDoListPK", "Name"); //legalEntities ddl ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); workDoneView.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name"); //service type ddl IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); workDoneView.ServiceTypes = new SelectList(serviceTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "ServiceTypePK", "Name"); //Work done ddl IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); workDoneView.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkTypePK", "Name"); //worksubtypes ddl if (workDoneView.WorkTypeFK != null) { IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); workDoneView.WorkSubtypes = new SelectList(workSubtypesRepository.GetValidByWorkType(Convert.ToInt32(workDoneView.WorkTypeFK)), "WorkSubtypePK", "Name", workDoneView.WorkSubtypeFK); } else { workDoneView.WorkSubtypes = new SelectList(new List <County>(), "WorkSubtypePK", "Name"); } //hours and minutes ddl workDoneView.Hours = GeneratorView.GenerateHours(); workDoneView.Minutes = GeneratorView.GenerateMinutes(); return(View(workDoneView)); } else { return(RedirectToAction("Index", "WorkDone")); } }
public ActionResult Add(int?workDoneFK) { WorkDoneAttachmentView workDoneAttachmentView = new WorkDoneAttachmentView(); //WorkDones ddl IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); workDoneAttachmentView.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("Description ASC").ToList(), "WorkDonePK", "Description"); if (workDoneFK != null) { workDoneAttachmentView.WorkDoneFK = workDoneFK; } return(View(workDoneAttachmentView)); }
public ActionResult Edit(int?workDoneAttachmentPK) { if (workDoneAttachmentPK != null) { IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneAttachment workDoneAttachment = workDoneAttachmentsRepository.GetWorkDoneAttachmentByPK((int)workDoneAttachmentPK); WorkDoneAttachmentView workDoneAttachmentView = new WorkDoneAttachmentView(); workDoneAttachmentView.ConvertFrom(workDoneAttachment, workDoneAttachmentView); //WorkDones ddl IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); workDoneAttachmentView.WorkDones = new SelectList(workDonesRepository.GetValid().OrderBy("Description ASC").ToList(), "WorkDonePK", "Description"); return(View(workDoneAttachmentView)); } else { return(RedirectToAction("Index", "WorkDoneAttachment")); } }