コード例 #1
0
        public ActionResult Add(ToDoListView toDoListView, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
                ToDoList             toDoList            = new ToDoList();

                toDoListView.ConvertTo(toDoListView, toDoList);

                toDoList.UserFK       = SecurityHelper.GetUserPKFromCookie();
                toDoList.CreationDate = DateTime.Now;

                toDoListsRepository.Add(toDoList);
                toDoListsRepository.SaveChanges();

                string[] legalEntitiesSelectedValues = new string[500];
                if (form["LegalEntityPK"] != null)
                {
                    legalEntitiesSelectedValues = ((string)form["LegalEntityPK"]).Split(',');
                }
                else
                {
                    legalEntitiesSelectedValues = null;
                }

                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

                if (legalEntitiesSelectedValues != null)
                {
                    // Add work dones
                    foreach (string legalEntity in legalEntitiesSelectedValues)
                    {
                        WorkDone workDone = new WorkDone();

                        workDone.ToDoListFK      = toDoList.ToDoListPK;
                        workDone.LegalEntityFK   = Convert.ToInt32(legalEntity);
                        workDone.CreatedWithToDo = true;

                        workDonesRepository.Add(workDone);
                    }

                    workDonesRepository.SaveChanges();
                }

                TempData["message"] = LayoutHelper.GetMessage("INSERT", toDoList.ToDoListPK);

                return(RedirectToAction("Index", "ToDoList"));
            }
            else
            {
                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name");

                return(View(toDoListView));
            }
        }
コード例 #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(ToDoListView toDoListView, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db);
                ToDoList             toDoList            = toDoListsRepository.GetToDoListByPK((int)toDoListView.ToDoListPK);
                toDoListView.ConvertTo(toDoListView, toDoList);

                toDoListsRepository.SaveChanges();

                string[] legalEntitiesSelectedValues = new string[500];
                if (form["LegalEntityPK"] != null)
                {
                    legalEntitiesSelectedValues = ((string)form["LegalEntityPK"]).Split(',');
                }
                else
                {
                    legalEntitiesSelectedValues = null;
                }

                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

                var legalEntitiesValueFromDB = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListView.ToDoListPK).Select(a => a.LegalEntityFK);

                if (legalEntitiesSelectedValues != null)
                {
                    // Add work dones
                    foreach (string legalEntity in legalEntitiesSelectedValues)
                    {
                        int legalEntityFK = Convert.ToInt32(legalEntity);

                        if (!legalEntitiesValueFromDB.Contains(legalEntityFK))
                        {
                            WorkDone workDone = new WorkDone();

                            workDone.ToDoListFK      = toDoList.ToDoListPK;
                            workDone.LegalEntityFK   = legalEntityFK;
                            workDone.CreatedWithToDo = true;

                            workDonesRepository.Add(workDone);
                        }
                    }

                    workDonesRepository.SaveChanges();

                    List <WorkDone> workDones = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListView.ToDoListPK).ToList();

                    // delete existing
                    foreach (WorkDone workDone in workDones)
                    {
                        int legalEntityFK = (int)workDone.LegalEntityFK;

                        if (!legalEntitiesSelectedValues.ToList().Contains(legalEntityFK.ToString()))
                        {
                            workDone.Deleted = true;

                            workDonesRepository.SaveChanges();
                        }
                    }
                }

                TempData["message"] = LayoutHelper.GetMessage("UPDATE", toDoList.ToDoListPK);

                return(RedirectToAction("Index", "ToDoList"));
            }
            else
            {
                IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db);

                var legalEntitiesSelectedValue = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListView.ToDoListPK).Select(a => a.LegalEntityFK);

                ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
                toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name", legalEntitiesSelectedValue);

                return(View(toDoListView));
            }
        }
コード例 #4
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));
            }
        }