public ActionResult AutocompleteLegalEntitiesOIB(string term) { ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); var legalEntities = legalEntitiesRepository.GetValidLegalEntities().Where(c => c.OIB.Contains(term)).OrderBy(x => x.OIB); return(Json(legalEntities.Select(c => new { value = c.OIB, value_id = c.LegalEntityPK }), JsonRequestBehavior.AllowGet)); }
public ActionResult Add(int?toDoListPK) { ToDoListView toDoListView = new ToDoListView(); if (toDoListPK != null) { IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); ToDoList toDoList = toDoListsRepository.GetToDoListByPK((int)toDoListPK); IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); toDoList.Finished = false; toDoListView.ConvertFrom(toDoList, toDoListView); var legalEntitiesSelectedValue = workDonesRepository.GetWorkDonesCreatedWithToDo((int)toDoListPK).Select(a => a.LegalEntityFK); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name", legalEntitiesSelectedValue); } else { ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); toDoListView.Companies = new MultiSelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("name ASC"), "LegalEntityPK", "Name"); } return(View(toDoListView)); }
public ActionResult Index() { IAssessmentsRepository assessmentsRepository = new AssessmentsRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IRisksRepository risksRepository = new RisksRepository(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"] : "AssessmentPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <AssessmentsView> assessments = AssessmentsView.GetHomeView(assessmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), risksRepository.GetValid()) .OrderBy(ordering); //legalEntities ddl ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name", Request.QueryString["legalEntityFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["LegalEntityFK"])) { int legalEntityFK = Convert.ToInt32(Request.QueryString["LegalEntityFK"]); assessments = assessments.Where(a => a.LegalEntityFK == legalEntityFK); } int assessmentCount = 0; if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); assessments = assessments.Where(c => c.AssessmentComment.Contains(searchString) || c.AssessmentDate.ToString().Contains(searchString) || c.LegalEntityName.Contains(searchString)); assessmentCount = assessments.Count(); } assessments = assessments.Page(page, pageSize); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); ViewData["numberOfRecords"] = assessmentCount; } else { ViewData["numberOfRecords"] = assessmentsRepository.GetValid().Count(); } int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("Assessment?" + url + "page=" + numberOfPages)); } else { return(View("Index", assessments.ToList())); } }
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)); } }
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 Index() { ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(db); IBanksRepository banksRepository = new BanksRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); LegalEntityBankView legalEntityBankView = new LegalEntityBankView(); 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"] : "LegalEntityBankPK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <LegalEntityBankView> legalEntitiesBanks = LegalEntityBankView.GetLegalEntityBankView(legalEntitiesBanksRepository.GetValid(), banksRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()) .OrderBy(ordering); //legalEntities ddl ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name", Request.QueryString["legalEntityFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); legalEntitiesBanks = legalEntitiesBanks.Where(c => c.LegalEntityName.Contains(searchString) || c.BankName.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["legalEntityFK"])) { int legalEntityFK = Convert.ToInt32(Request.QueryString["legalEntityFK"]); legalEntitiesBanks = legalEntitiesBanks.Where(c => c.LegalEntityFK == legalEntityFK); } legalEntitiesBanks = legalEntitiesBanks.Page(page, pageSize); ViewData["numberOfRecords"] = legalEntitiesBanksRepository.GetValid().Count(); int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("LegalEntityBank?" + url + "page=" + numberOfPages)); } else { return(View("Index", legalEntitiesBanks.ToList())); } }
public ActionResult Add(int?toDoListFK) { WorkDoneView workDoneView = new WorkDoneView(); //to do list ddl IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); workDoneView.ToDoLists = new SelectList(toDoListsRepository.GetNotFinished().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 type ddl IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); workDoneView.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkTypePK", "Name"); //worksubtypes ddl workDoneView.WorkSubtypes = new SelectList(new List <County>(), "WorkSubtypePK", "Name"); //hours and minutes ddl workDoneView.Hours = GeneratorView.GenerateHours(); workDoneView.Minutes = GeneratorView.GenerateMinutes(); if (toDoListFK != null) { workDoneView.ToDoListFK = toDoListFK; } workDoneView.ServiceTypeFK = 1; return(View(workDoneView)); }
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)); } }
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)); } }
public ActionResult Index() { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneView workDoneView = new WorkDoneView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); IUsersRepository usersRepository = new UsersRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(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"] : "WorkDonePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); IQueryable <WorkDoneView> workDones = WorkDoneView.GetWorkDoneView(workDonesRepository.GetValid(), toDoListsRepository.GetValid(), workDoneAttachmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), workTypesRepository.GetValid(), workSubtypesRepository.GetValid(), serviceTypesRepository.GetValid(), usersRepository.GetValid()) .OrderBy(ordering); //grid filters ddl ViewBag.ToDoLists = new SelectList(toDoListsRepository.GetValid().OrderBy("Name ASC").ToList(), "ToDoListPK", "Name", Request.QueryString["toDoListFK"]); ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").OrderBy("name").ToList(), "LegalEntityPK", "Name", Request.QueryString["legalEntityFK"]); ViewBag.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("name").OrderBy("Name ASC").ToList(), "WorkTypePK", "Name", Request.QueryString["workTypeFK"]); if (!String.IsNullOrWhiteSpace(Request.QueryString["workTypeFK"])) { int workTypeFK = Convert.ToInt32(Request.QueryString["workTypeFK"]); ViewBag.WorkSubtypes = new SelectList(workSubtypesRepository.GetValidByWorkType(workTypeFK).OrderBy("name").ToList(), "WorkSubtypePK", "Name", Request.QueryString["workSubtypeFK"]); } else { ViewBag.WorkSubtypes = new SelectList(new List <County>(), "WorkSubtypePK", "Name"); } ViewBag.Users = new SelectList(usersRepository.GetValid().OrderBy("username").ToList(), "UserPK", "Username", Request.QueryString["userFK"]); // search construct if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"])) { string searchString = Request.QueryString["searchString"].ToString(); workDones = workDones.Where(c => c.Description.Contains(searchString) || c.Comment.Contains(searchString)); } if (!String.IsNullOrWhiteSpace(Request.QueryString["createdWithToDo"])) { bool createdWithToDo = Convert.ToBoolean(Request.QueryString["createdWithToDo"]); workDones = workDones.Where(c => c.CreatedWithToDo == createdWithToDo); } else { workDones = workDones.Where(c => c.Description != null && c.WorkTypeName != null && c.WorkSubtypeName != null && c.ServiceTypeName != null && c.TimeSpent != null); } if (!String.IsNullOrWhiteSpace(Request.QueryString["toDoListFK"])) { int toDoListFK = Convert.ToInt32(Request.QueryString["toDoListFK"]); workDones = workDones.Where(c => c.ToDoListFK == toDoListFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["legalEntityFK"])) { int legalEntityFK = Convert.ToInt32(Request.QueryString["legalEntityFK"]); workDones = workDones.Where(c => c.LegalEntityFK == legalEntityFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["workTypeFK"])) { int workTypeFK = Convert.ToInt32(Request.QueryString["workTypeFK"]); workDones = workDones.Where(c => c.WorkTypeFK == workTypeFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["workSubtypeFK"])) { int workSubtypeFK = Convert.ToInt32(Request.QueryString["workSubtypeFK"]); workDones = workDones.Where(c => c.WorkSubtypeFK == workSubtypeFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["userFK"])) { int userFK = Convert.ToInt32(Request.QueryString["userFK"]); workDones = workDones.Where(c => c.UserFK == userFK); } if (!String.IsNullOrWhiteSpace(Request.QueryString["date"])) { DateTime Date = DateTime.ParseExact(Request.QueryString["date"], "dd.MM.yyyy.", null); workDones = workDones.Where(c => c.Date == Date); } workDones = workDones.Page(page, pageSize); ViewData["numberOfRecords"] = workDones.Count(); int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize; if (page > numberOfPages) { string url = LinkHelper.getQueryStringArray(new string[] { "page" }); return(Redirect("WorkDone?" + url + "page=" + numberOfPages)); } else { return(View("Index", workDones.ToList())); } }
public static List <List <LegalEntityBankAuditView> > GetLegalEntityBanksAuditView(ObjectContext context, int legalEntityFK) { IBanksRepository banksRepository = new BanksRepository(context); ILegalEntitiesRepository LegalEntitiesRepository = new LegalEntitiesRepository(context); ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(context); // get all legalEntity bank records List <LegalEntityBankView> legalEntitiesBanks = LegalEntityBankView.GetLegalEntityBankView(legalEntitiesBanksRepository.GetAll(), banksRepository.GetValid(), LegalEntitiesRepository.GetValidLegalEntities()) .Where(c => c.LegalEntityFK == legalEntityFK) .ToList(); List <List <LegalEntityBankAuditView> > LegalEntityBanksListList = new List <List <LegalEntityBankAuditView> >(); foreach (LegalEntityBankView legalEntityBank in legalEntitiesBanks) { LegalEntityBanksListList.Add(LegalEntityBankAuditView.GetLegalEntityBankAuditView(context, legalEntityBank.LegalEntityBankPK)); } return(LegalEntityBanksListList); }
public ActionResult WorkDoneExportToExcel( int?toDoListFK, int?legalEntityFK, int?workTypeFK, int?workSubtypeFK, int?serviceTypeFK, int?userFK, string dateFrom, string dateTo, int?timeSpentFrom, int?timeSpentTo, int?numberOfAttachmentsFrom, int?numberOfAttachmentsTo, string description, bool ShowBasicInfo, bool ShowOrdinal, bool ShowID, bool ShowToDoList, bool ShowLegalEntity, bool ShowWorkType, bool ShowWorkSubtype, bool ShowServiceType, bool ShowDate, bool ShowUsername, bool ShowDescription, bool ShowTimeSpent, bool ShowComment, bool ShowAttachments) { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneView workDoneView = new WorkDoneView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); IUsersRepository usersRepository = new UsersRepository(db); string sortOrder = !string.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !string.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "WorkDonePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); if (legalEntityFK != null) { ViewBag.LegalEntity = legalEntitiesRepository.GetLegalEntityByPK((int)legalEntityFK).Name; } if (toDoListFK != null) { ViewBag.ToDoList = toDoListsRepository.GetToDoListByPK((int)toDoListFK).Name; } if (workTypeFK != null) { ViewBag.WorkType = workTypesRepository.GetWorkTypeByPK((int)workTypeFK).Name; } if (workSubtypeFK != null) { ViewBag.WorkSubtype = workSubtypesRepository.GetWorkSubtypeByPK((int)workSubtypeFK).Name; } if (userFK != null) { ViewBag.User = usersRepository.GetUserByUserID((int)userFK).Username; } DateTime?dateFromTime = null; DateTime?dateToTime = null; if (dateFrom != null && dateFrom != "") { dateFromTime = DateTime.ParseExact(dateFrom, "dd.MM.yyyy.", null); } if (dateTo != null && dateTo != "") { dateToTime = DateTime.ParseExact(dateTo, "dd.MM.yyyy.", null); } // Applying filters IQueryable <WorkDone> workDonesFiltered = WorkDoneView.GetWorkDonesReport(db, toDoListFK, legalEntityFK, workTypeFK, workSubtypeFK, serviceTypeFK, userFK, dateFromTime, dateToTime, timeSpentFrom, timeSpentTo, numberOfAttachmentsFrom, numberOfAttachmentsTo, description); IQueryable <WorkDoneView> workDones = WorkDoneView.GetWorkDoneView(workDonesFiltered, toDoListsRepository.GetValid(), workDoneAttachmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), workTypesRepository.GetValid(), workSubtypesRepository.GetValid(), serviceTypesRepository.GetValid(), usersRepository.GetValid()) .OrderBy(ordering); var workDonesList = workDones.ToList(); var columns = new Dictionary <string, int>(); var ms = new MemoryStream(); using (var package = new ExcelPackage(ms)) { ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Izvršeni posao"); var columnPosition = 1; Action <bool, string> setColumnHeader = (columnVisible, columnName) => { if (columnVisible) { worksheet.Cells[1, columnPosition].Value = columnName; worksheet.Cells[1, columnPosition].Style.Font.Bold = true; columns.Add(columnName, columnPosition++); } }; setColumnHeader(ShowOrdinal, "#"); setColumnHeader(ShowID, "ID"); setColumnHeader(ShowToDoList, "Obaveza"); setColumnHeader(ShowLegalEntity, "Tvrtka"); setColumnHeader(ShowWorkType, "Vrsta rada"); setColumnHeader(ShowWorkSubtype, "Vrsta posla"); setColumnHeader(ShowServiceType, "Vrsta usluge"); setColumnHeader(ShowDate, "Datum izvršenja"); setColumnHeader(ShowUsername, "Korisnik"); setColumnHeader(ShowDescription, "Opis"); setColumnHeader(ShowTimeSpent, "Utrošeno vrijeme"); setColumnHeader(ShowComment, "Važna napomena"); setColumnHeader(ShowAttachments, "Prilozi"); Action <int, bool, string, object> setRowValue = (ri, columnVisible, columnName, value) => { if (columnVisible) { worksheet.Cells[ri, columns[columnName]].Value = value; } }; var rowIndex = 2; foreach (var item in workDonesList) { setRowValue(rowIndex, ShowOrdinal, "#", rowIndex - 1); setRowValue(rowIndex, ShowID, "ID", item.WorkDonePK); setRowValue(rowIndex, ShowToDoList, "Obaveza", item.ToDoListName); setRowValue(rowIndex, ShowLegalEntity, "Tvrtka", item.LegalEntityName); setRowValue(rowIndex, ShowWorkType, "Vrsta rada", item.WorkTypeName); setRowValue(rowIndex, ShowWorkSubtype, "Vrsta posla", item.WorkSubtypeName); setRowValue(rowIndex, ShowServiceType, "Vrsta usluge", item.ServiceTypeName); setRowValue(rowIndex, ShowDate, "Datum izvršenja", item.Date?.ToString("dd.MM.yyyy.")); setRowValue(rowIndex, ShowUsername, "Korisnik", item.UserUsername); setRowValue(rowIndex, ShowDescription, "Opis", item.Description); setRowValue(rowIndex, ShowTimeSpent, "Utrošeno vrijeme", LinkHelper.calculateTimeSpent(item.TimeSpent)); setRowValue(rowIndex, ShowComment, "Važna napomena", item.Comment); setRowValue(rowIndex, ShowAttachments, "Prilozi", item.WorkDoneAttachmentsCount); rowIndex++; } worksheet.Calculate(); worksheet.Cells.AutoFitColumns(0); package.Save(); } ms.Seek(0, SeekOrigin.Begin); return(new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"Izvršeni posao {DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")}.xlsx" }); }
public ActionResult WorkDone(int?toDoListFK, int?legalEntityFK, int?workTypeFK, int?workSubtypeFK, int?serviceTypeFK, int?userFK, string dateFrom, string dateTo, int?timeSpentFrom, int?timeSpentTo, int?numberOfAttachmentsFrom, int?numberOfAttachmentsTo, string description) { IWorkDonesRepository workDonesRepository = new WorkDonesRepository(db); IWorkDoneAttachmentsRepository workDoneAttachmentsRepository = new WorkDoneAttachmentsRepository(db); WorkDoneView workDoneView = new WorkDoneView(); IContractsRepository contractsRepository = new ContractsRepository(db); ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IToDoListsRepository toDoListsRepository = new ToDoListsRepository(db); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IWorkTypesRepository workTypesRepository = new WorkTypesRepository(db); IWorkSubtypesRepository workSubtypesRepository = new WorkSubtypesRepository(db); IServiceTypesRepository serviceTypesRepository = new ServiceTypesRepository(db); IUsersRepository usersRepository = new UsersRepository(db); string sortOrder = !string.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC"; string sortColumn = !string.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "WorkDonePK"; string ordering = sortColumn + " " + sortOrder; ordering = ordering.Trim(); //grid filters ddl ViewBag.ToDoLists = new SelectList(toDoListsRepository.GetValid().OrderBy("Name ASC").ToList(), "ToDoListPK", "Name", toDoListFK); ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name", legalEntityFK); ViewBag.WorkTypes = new SelectList(workTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkTypePK", "Name", workTypeFK); ViewBag.WorkSubtypes = new SelectList(workSubtypesRepository.GetValid().OrderBy("Name ASC").ToList(), "WorkSubtypePK", "Name", workSubtypeFK); ViewBag.ServiceTypes = new SelectList(serviceTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "ServiceTypePK", "Name", serviceTypeFK); ViewBag.Users = new SelectList(usersRepository.GetValid().OrderBy("Username ASC").ToList(), "UserPK", "Username", userFK); if (legalEntityFK != null) { ViewBag.LegalEntity = legalEntitiesRepository.GetLegalEntityByPK((int)legalEntityFK).Name; } if (toDoListFK != null) { ViewBag.ToDoList = toDoListsRepository.GetToDoListByPK((int)toDoListFK).Name; } if (workTypeFK != null) { ViewBag.WorkType = workTypesRepository.GetWorkTypeByPK((int)workTypeFK).Name; } if (workSubtypeFK != null) { ViewBag.WorkSubtype = workSubtypesRepository.GetWorkSubtypeByPK((int)workSubtypeFK).Name; } if (userFK != null) { ViewBag.User = usersRepository.GetUserByUserID((int)userFK).Username; } DateTime?dateFromTime = null; DateTime?dateToTime = null; if (dateFrom != null && dateFrom != "") { dateFromTime = DateTime.ParseExact(dateFrom, "dd.MM.yyyy.", null); } if (dateTo != null && dateTo != "") { dateToTime = DateTime.ParseExact(dateTo, "dd.MM.yyyy.", null); } // Applying filters IQueryable <WorkDone> workDonesFiltered = WorkDoneView.GetWorkDonesReport(db, toDoListFK, legalEntityFK, workTypeFK, workSubtypeFK, serviceTypeFK, userFK, dateFromTime, dateToTime, timeSpentFrom, timeSpentTo, numberOfAttachmentsFrom, numberOfAttachmentsTo, description); IQueryable <WorkDoneView> workDones = WorkDoneView.GetWorkDoneView(workDonesFiltered, toDoListsRepository.GetValid(), workDoneAttachmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), workTypesRepository.GetValid(), workSubtypesRepository.GetValid(), serviceTypesRepository.GetValid(), usersRepository.GetValid()) .OrderBy(ordering); // Excluding temporary deleted items from view workDonesPKPKsToExclude = new List <int>(); // Empty session on first request if (Request.QueryString.Count == 0) { Session["workDonesPKPKsToExclude"] = null; } if (Session["workDonesPKPKsToExclude"] != null) { workDonesPKPKsToExclude = (List <int>)Session["workDonesPKPKsToExclude"]; workDones = workDones.Where(c => !workDonesPKPKsToExclude.Contains(c.WorkDonePK)); } return(View("WorkDone", workDones.ToList())); }
//[PITAuthorize(Roles = "add, edit, view, delete")] public ActionResult LegalEntity(int?legalEntityFK, string ShowBasicInfo, string ShowLegalEntityHistory, string ShowLegalEntityLegalRepresentatives, string ShowLegalEntityLegalRepresentativesHistory, string ShowLegalEntityBanks, string ShowLegalEntityBanksHistory, string ShowContracts, string ShowBranches, string ShowBranchesHistory, string ShowLegalEntityOwners, string ShowLegalEntityOwnersHistory) { LegalEntityView legalEntityView = new LegalEntityView(); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); if (legalEntityFK != null) { int legalEntityPK = (int)legalEntityFK; if (ShowBasicInfo == "on" || ShowBasicInfo == "true") { legalEntityView = LegalEntityView.GetLegalEntityReport(db, legalEntityPK); } if (ShowLegalEntityLegalRepresentatives == "on" || ShowLegalEntityLegalRepresentatives == "true") { IPhysicalEntitiesRepository physicalEntitiesRepository = new PhysicalEntitiesRepository(db); ILegalEntityLegalRepresentativesRepository legalEntityLegalRepresentativesRepository = new LegalEntityLegalRepresentativesRepository(db); IQueryable <LegalEntityLegalRepresentativeView> legalEntityLegalRepresentatives = LegalEntityLegalRepresentativeView.GetLegalEntityLegalRepresentativeView(legalEntityLegalRepresentativesRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), physicalEntitiesRepository.GetValid()); ViewBag.LegalEntityLegalRepresentatives = legalEntityLegalRepresentatives.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } if (ShowLegalEntityBanks == "on" || ShowLegalEntityBanks == "true") { ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(db); IBanksRepository banksRepository = new BanksRepository(db); IQueryable <LegalEntityBankView> legalEntitiesBanks = LegalEntityBankView.GetLegalEntityBankView(legalEntitiesBanksRepository.GetValid(), banksRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()); ViewBag.LegalEntityBanks = legalEntitiesBanks.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } if (ShowContracts == "on" || ShowContracts == "true") { IContractsRepository contractsRepository = new ContractsRepository(db); IAnnexContractsRepository annexContractsRepository = new AnnexContractsRepository(db); IQueryable <ContractView> contracts = ContractView.GetContractsView(contractsRepository.GetValid(), annexContractsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()); ViewBag.Contracts = contracts.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } if (ShowBranches == "on" || ShowBranches == "true") { ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db); IQueryable <LegalEntityBranchView> legalEntityBranches = LegalEntityBranchView.GetLegalEntityBranchView(legalEntityBranchesRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities()); ViewBag.Branches = legalEntityBranches.Where(c => c.LegalEntityFK == legalEntityPK).ToList(); } // history if (ShowLegalEntityHistory == "on" || ShowLegalEntityHistory == "true") { List <LegalEntityAuditView> legalEntityHistory = LegalEntityAuditView.GetLegalEntityAuditView(db, legalEntityPK); ViewBag.legalEntityHistory = legalEntityHistory.ToList(); } if (ShowLegalEntityBanksHistory == "on" || ShowLegalEntityBanksHistory == "true") { List <List <LegalEntityBankAuditView> > legalEntityBanksHistory = LegalEntityBankAuditView.GetLegalEntityBanksAuditView(db, legalEntityPK); List <DateTime> legalEntityBanksDatesHistory = new List <DateTime>(); foreach (List <LegalEntityBankAuditView> legalEntityBank in legalEntityBanksHistory) { foreach (LegalEntityBankAuditView legalEntityBankAuditView in legalEntityBank) { if (!legalEntityBanksDatesHistory.Contains(legalEntityBankAuditView.ChangeDate.Value)) { legalEntityBanksDatesHistory.Add(legalEntityBankAuditView.ChangeDate.Value); } } } ViewBag.legalEntityBanksDatesHistory = legalEntityBanksDatesHistory.OrderBy(c => c.Date).ToList(); ViewBag.legalEntityBanksHistory = legalEntityBanksHistory; } if (ShowLegalEntityLegalRepresentativesHistory == "on" || ShowLegalEntityLegalRepresentativesHistory == "true") { List <List <LegalEntityLegalRepresentativeAuditView> > legalEntityLegalRepresentativesHistory = LegalEntityLegalRepresentativeAuditView.GetLegalEntityLegalRepresentativesAuditView(db, legalEntityPK); ViewBag.legalEntityLegalRepresentativesHistory = legalEntityLegalRepresentativesHistory; } if (ShowLegalEntityOwnersHistory == "on" || ShowLegalEntityOwnersHistory == "true") { List <List <LegalEntityOwnerAuditView> > legalEntityOwnersHistory = LegalEntityOwnerAuditView.GetLegalEntityOwnersAuditView(db, legalEntityPK); ViewBag.legalEntityOwnersHistory = legalEntityOwnersHistory; } if (ShowBranchesHistory == "on" || ShowBranchesHistory == "on") { List <List <LegalEntityBranchAuditView> > legalEntityBranchesHistory = LegalEntityBranchAuditView.GetLegalEntityBranchesAuditView(db, legalEntityPK); ViewBag.legalEntityBranchesHistory = legalEntityBranchesHistory; } } return(View(legalEntityView)); }
public static IQueryable <LegalEntityView> GetLegalEntitiesReport(ObjectContext db, string Name, string OIB, string MB, string MBS, int?BankPK, int?TaxPK, int?FormPK, int?ActivityPK, int?SubstationPK, int?CommercialCourtPK, int?numberOfEmployeesFrom, int?numberOfEmployeesTo, int?fundamentalCapitalFrom, int?fundamentalCapitalTo, bool?TouristOffice, bool?MonumentAnnuity) { ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); IQueryable <LegalEntity> legalEntityTable = legalEntitiesRepository.GetValidLegalEntities(); IBanksRepository banksRepository = new BanksRepository(db); ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(db); var banksTable = banksRepository.GetValid(); var legalEntitiesBanksTable = legalEntitiesBanksRepository.GetValid(); IQueryable <LegalEntity> legalEntitiesFiltered = legalEntitiesRepository.GetValid(); if (legalEntitiesFiltered.Count() > 0) { if (!string.IsNullOrWhiteSpace(Name)) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByName(Name); } if (!string.IsNullOrWhiteSpace(OIB)) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByOIB(OIB); } if (!string.IsNullOrWhiteSpace(MB)) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByMB(MB); } if (!string.IsNullOrWhiteSpace(MBS)) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByMBS(MBS); } if (numberOfEmployeesFrom != null || numberOfEmployeesTo != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByEmployeesRange(numberOfEmployeesFrom, numberOfEmployeesTo); } if (fundamentalCapitalFrom != null || fundamentalCapitalTo != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByFundamentalCapitalRange(fundamentalCapitalFrom, fundamentalCapitalTo); } if (BankPK != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByBank(db, BankPK); } if (TaxPK != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByTax(TaxPK); } if (SubstationPK != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesBySubstation(SubstationPK); } if (CommercialCourtPK != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByCommercialCourt(CommercialCourtPK); } if (FormPK != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByForm(FormPK); } if (ActivityPK != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByActivity(ActivityPK); } if (TouristOffice != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByTouristOffice(TouristOffice); } if (MonumentAnnuity != null) { legalEntitiesFiltered = legalEntitiesFiltered.GetLegalEntitiesByMonumentAnnuity(MonumentAnnuity); } } IQueryable <LegalEntityView> legalEntityViewList = (from t1 in legalEntitiesFiltered from t2 in legalEntitiesBanksTable.Where(b => b.LegalEntityFK == t1.LegalEntityPK).DefaultIfEmpty() from t3 in banksTable.Where(b => b.BankPK == t2.BankFK).DefaultIfEmpty() select new LegalEntityView { LegalEntityPK = t1.LegalEntityPK, Name = t1.Name, ShortName = t1.ShortName != null ? t1.ShortName : "", OIB = t1.OIB != null ? t1.OIB : "", MB = t1.MB != null ? t1.MB : "", MBS = t1.MBS != null ? t1.MBS : "", FormName = t1.Form.Name != null ? t1.Form.Name : "" }).Distinct().AsQueryable <LegalEntityView>(); return(legalEntityViewList); }
public ActionResult Edit(AssessmentsView assessmentView, FormCollection form) { if (ModelState.IsValid) { IAssessmentsRepository assessmentsRepository = new AssessmentsRepository(db); Assessment assessment = assessmentsRepository.GetAssessmentByPK((int)assessmentView.AssessmentPK); IAssessmentAnswersRepository assessmentAnswersRepository = new AssessmentAnswersRepository(db); // Delete old values assessmentAnswersRepository.Delete(a => a.AssessmentFK == assessment.AssessmentPK); // Add new values IAssessmentGroupsRepository assessmentGroupsRepository = new AssessmentGroupsRepository(db); IAssessmentQuestionsRepository assessmentQuestionsRepository = new AssessmentQuestionsRepository(db); IAssessmentTypesRepository assessmentTypesRepository = new AssessmentTypesRepository(db); assessmentView.AssessmentsTypesView = AssessmentsView.FillQuiz(assessmentTypesRepository.GetValid(), assessmentGroupsRepository, assessmentQuestionsRepository, form); // Fetching answered type AssessmentsTypeView atw = assessmentView.AssessmentsTypesView.Where(a => a.AssessmentType.AssessmentTypePK == assessmentView.AssessmentTypeFK).First(); List <AssessmentAnswers> assessmentAnswers = AssessmentAnswerView.ExtractQuizAnswers(atw, assessment.AssessmentPK); ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); LegalEntity legalEntity = legalEntitiesRepository.GetLegalEntityByPK((int)assessmentView.LegalEntityFK); bool activityHighRisky = legalEntity.Activity.HighRisk != null && (bool)legalEntity.Activity.HighRisk ? true : false; bool activityLowRisky = legalEntity.Activity.LowRisk != null && (bool)legalEntity.Activity.LowRisk ? true : false; bool headquarterCountryRisky = legalEntity.Country.Risk != null && (bool)legalEntity.Country.Risk ? true : false; IRisksRepository risksRepository = new RisksRepository(db); if (activityHighRisky || headquarterCountryRisky) // check explicitly if related legalEntity activity is high risk { assessmentView.RiskFK = risksRepository.GetRiskByName("Visok").RiskPK; } else if (activityLowRisky) // check explicitly if related legalEntity activity is low risk { assessmentView.RiskFK = risksRepository.GetRiskByName("Nizak").RiskPK; } else // run assesment quiz { ILegalEntityOwnersRepository legalEntityOwnersRepository = new LegalEntityOwnersRepository(db); IQueryable <LegalEntityOwner> legalEntityOwnersTable = legalEntityOwnersRepository.GetValid(); ICountriesRepository countriesRepository = new CountriesRepository(db); IActivitiesRepository activitiesRepository = new ActivitiesRepository(db); List <LegalEntityOwner> coList = legalEntityOwnersRepository.GetFirstLegalEntityOwnersForLegalEntity((int)assessmentView.LegalEntityFK).ToList(); legalEntityOwnersTable = LegalEntityOwnerView.GetLegalEntityOwnersForLegalEntity(Convert.ToInt32(assessmentView.LegalEntityFK), coList, legalEntityOwnersTable); IQueryable <LegalEntity> legalEntityView = LegalEntityOwnerView.GetRelatedLegalEntities(legalEntityOwnersTable, legalEntitiesRepository.GetValid(), countriesRepository.GetValid(), activitiesRepository.GetValid()); // check owners risks bool ownersResidenceCountryRisky = false; bool ownersActivitiesHighlyRisky = false; bool ownersActivitiesLowRisky = false; if (legalEntityView.Count() > 0) { if (legalEntityView.ToList().TrueForAll(le => le.Country.Risk == null || (le.Country.Risk != null && (bool)le.Country.Risk != true)) == false) { ownersResidenceCountryRisky = true; } if (legalEntityView.ToList().TrueForAll(le => le.Activity == null || (le.Activity.HighRisk == null || (le.Activity.HighRisk != null && (bool)le.Activity.HighRisk != true))) == false) { ownersActivitiesHighlyRisky = true; } if (legalEntityView.ToList().TrueForAll(le => le.Activity == null || (le.Activity.LowRisk == null || (le.Activity.LowRisk != null && (bool)le.Activity.LowRisk != true))) == false) { ownersActivitiesLowRisky = true; } } // check form bool allAnswersYes = false; bool allAnswersNo = false; bool mixedAnswers = false; if (assessmentAnswers.TrueForAll(aa => aa.AssessmentAnswer != null && (bool)aa.AssessmentAnswer == true)) { allAnswersYes = true; } if (assessmentAnswers.TrueForAll(aa => aa.AssessmentAnswer != null && (bool)aa.AssessmentAnswer == false)) { allAnswersNo = true; } if (allAnswersYes == false && allAnswersNo == false) { mixedAnswers = true; } // check general conditions if (ownersActivitiesLowRisky) { assessmentView.RiskFK = risksRepository.GetRiskByName("Nizak").RiskPK; } else if (allAnswersYes || ownersResidenceCountryRisky || ownersActivitiesHighlyRisky) { assessmentView.RiskFK = risksRepository.GetRiskByName("Visok").RiskPK; } else if (allAnswersNo || mixedAnswers) { assessmentView.RiskFK = risksRepository.GetRiskByName("Srednji").RiskPK; } } if (assessmentAnswers.Count() > 0) { assessmentAnswersRepository.AddAll(assessmentAnswers); assessmentAnswersRepository.SaveChanges(); } assessmentView.ConvertTo(assessmentView, assessment); assessmentsRepository.SaveChanges(); TempData["message"] = LayoutHelper.GetMessage("UPDATE", assessment.AssessmentPK); return(RedirectToAction("Index", "Assessment")); } else { IAssessmentGroupsRepository assessmentGroupsRepository = new AssessmentGroupsRepository(db); IAssessmentQuestionsRepository assessmentQuestionsRepository = new AssessmentQuestionsRepository(db); //Assessment types ddl IAssessmentTypesRepository assessmentTypesRepository = new AssessmentTypesRepository(db); assessmentView.AssessmentTypes = new SelectList(assessmentTypesRepository.GetValid().OrderBy("Name ASC").ToList(), "AssessmentTypePK", "Name"); //legalEntities ddl ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db); assessmentView.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().ToList(), "LegalEntityPK", "Name"); assessmentView.AssessmentsTypesView = AssessmentsView.FillQuiz(assessmentTypesRepository.GetValid(), assessmentGroupsRepository, assessmentQuestionsRepository, form); return(View(assessmentView)); } }