Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
 public void ConvertTo(WorkDoneAttachmentView workDoneAttachmentView, WorkDoneAttachment workDoneAttachment)
 {
     workDoneAttachment.WorkDoneAttachmentPK = workDoneAttachmentView.WorkDoneAttachmentPK;
     workDoneAttachment.WorkDoneFK           = workDoneAttachmentView.WorkDoneFK;
     workDoneAttachment.AttachmentFK         = workDoneAttachmentView.AttachmentFK;
     workDoneAttachment.Deleted = workDoneAttachmentView.Deleted;
 }
Esempio n. 3
0
        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"));
            }
        }
Esempio n. 4
0
        public ActionResult Delete(int?workDoneAttachmentPK)
        {
            IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db);

            if (workDoneAttachmentPK != null)
            {
                WorkDoneAttachment workDoneAttachment = workDoneAttachmentsRepository.GetWorkDoneAttachmentByPK((int)workDoneAttachmentPK);

                workDoneAttachment.Deleted = true;

                workDoneAttachmentsRepository.SaveChanges();
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
        }
Esempio n. 5
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));
            }
        }