예제 #1
0
        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"));
            }
        }
예제 #2
0
        public ActionResult Delete(int?workDonePK)
        {
            IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

            if (workDonePK != null)
            {
                WorkDone workDone = workDonesRepository.GetWorkDoneByPK((int)workDonePK);

                workDone.Deleted = true;

                workDonesRepository.SaveChanges();

                TempData["message"] = LayoutHelper.GetMessage("DELETE", workDone.WorkDonePK);
            }

            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
예제 #3
0
        public ActionResult Edit(WorkDoneView workDoneView, FormCollection form, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                string sessionToken = Audit.GenerateNewSessionToken();

                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);
                WorkDone             workDone            = workDonesRepository.GetWorkDoneByPK((int)workDoneView.WorkDonePK);

                // set last user as entry creator
                if (workDone.UserFK == null)
                {
                    workDone.UserFK = SecurityHelper.GetUserPKFromCookie();
                }

                if (workDone.CreationDate == null)
                {
                    workDone.CreationDate = DateTime.Now;
                }

                workDoneView.ConvertTo(workDoneView, workDone);

                workDonesRepository.SaveChanges(sessionToken);

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", workDone.WorkDonePK);

                int workDoneFK = workDone.WorkDonePK;

                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", "WorkDone"));
            }
            else
            {
                //to do list ddl
                IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
                workDoneView.ToDoLists = new SelectList(toDoListsRepository.GetValid().OrderBy("Name ASC").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 (!String.IsNullOrWhiteSpace(form["WorkTypeFK"]))
                {
                    IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db);
                    workDoneView.WorkSubtypes = new SelectList(workSubtypesRepository.GetValidByWorkType(Convert.ToInt32(form["WorkTypeFK"])), "WorkSubtypePK", "Name", form["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));
            }
        }