public ActionResult EditCase(int id) { ApplicationUser manager = new ApplicationUser(WFEntities, this.Username); FlowInfo flowInfo = manager.GetFlowAndCase(id); var properties = manager.GetProperties(id); ViewBag.Properties = properties; var attachments = manager.GetAttachments(id); ViewBag.Attachments = attachments; ViewBag.FinalNotifyUsers = manager.GetFinalNotifyUsers(id); var flowType = WFEntities.WF_FlowTypes.FirstOrDefault(p => p.FlowTypeId == flowInfo.FlowTypeId); ViewBag.FlowType = flowType; ViewBag.HasCoverDuties = WFEntities.WF_FlowGroups.FirstOrDefault(p => p.FlowTypeId == flowInfo.FlowTypeId && p.StatusId > 0)?.HasCoverUsers; ViewBag.LeaveTypes = WFUtilities.GetLeaveType(RouteData.Values["lang"] as string); if (flowType.TemplateType.HasValue) { if (flowType.TemplateType.Value == 1) { ViewBag.Cities = WFEntities.Cities.Where(p => p.CountryCode == Country).AsNoTracking().ToArray(); } else if (flowType.TemplateType.Value == 7) { var prop = properties.PropertyInfo.FirstOrDefault(p => p.PropertyName.ToLower().Equals("brand") && p.StatusId < 0); if (prop != null) { var brand = properties.Values.FirstOrDefault(p => p.PropertyId == prop.FlowPropertyId)?.StringValue; var shopList = WFEntities.BLSShopView .Where(s => s.Brand.ToLower().Equals(brand.ToLower())) .Select(s => new { s.ShopCode, s.ShopName }) .ToDictionary(s => s.ShopCode, s => s.ShopName); ViewBag.ShopList = shopList; } } else if (flowType.TemplateType.Value == 2) { UserStaffInfo userInfo = WFUtilities.GetUserStaffInfo(this.Username); double balance = userInfo?.LeaveBalance ?? 0; double notstarted = manager.GetNotStartedBalance(Username); double unapproved = manager.GetUnApprovedBalance(Username); ViewBag.DisplayBalance = notstarted + balance; ViewBag.ValidBalance = balance > unapproved ? balance - unapproved : 0; } } return(PartialView(flowInfo)); }
public async Task <ActionResult> ChangePassword(string Password, string NewPassword, string ConfirmPassword) { if (User.Identity.Name == "Admin") { return(this.ShowErrorInModal("Admin cannot change password")); } if (NewPassword == ConfirmPassword) { LoginApiClient login = new LoginApiClient(); UserStaffInfo userInfo = WFUtilities.GetUserStaffInfo(this.Username); RequestResult <BoolResult> res = await login.ChangeUserPasswordAsync(User.Identity.Name, Password, NewPassword, userInfo.Country); if (!string.IsNullOrEmpty(res.ReturnValue.ret_msg)) { return(this.ShowErrorInModal(res.ReturnValue.ret_msg)); } return(this.ShowSuccessModal(StringResource.PASSWORD_CHANGE)); } return(this.ShowErrorInModal(StringResource.PASSWORD_INCONSISTENT)); }
public ActionResult FillFormValue(int flowtypeid) { ViewBag.Country = Country; UserStaffInfo userInfo = WFUtilities.GetUserStaffInfo(this.Username); ViewBag.CurrentDep = userInfo?.DepartmentName; WF_FlowTypes flowType = WFEntities.WF_FlowTypes.FirstOrDefault(p => p.FlowTypeId == flowtypeid && p.StatusId > 0); ViewBag.FlowType = flowType; if (flowType?.TemplateType.HasValue == true) { if (flowType.TemplateType.Value == (int)FlowTemplateType.DynamicTemplate) { var props = WFEntities.WF_FlowGroups.AsNoTracking() .Include("WF_FlowPropertys") .FirstOrDefault(p => p.FlowTypeId == flowtypeid && p.StatusId > 0)?.WF_FlowPropertys.ToArray(); return(PartialView("FillDynamicFormValue", props)); } if (flowType.TemplateType.Value == (int)FlowTemplateType.StoreApprovalTemplate) { ViewBag.Cities = WFEntities.Cities.Where(p => p.CountryCode == Country).AsNoTracking().ToArray(); } else if (flowType.TemplateType.Value == (int)FlowTemplateType.LeaveTemplate) { ApplicationUser manager = new ApplicationUser(WFEntities, this.Username); double balance = userInfo?.LeaveBalance ?? 0; double notstarted = manager.GetNotStartedBalance(Username); double unapproved = manager.GetUnApprovedBalance(Username); ViewBag.NotStartedBalance = notstarted; ViewBag.APIReturnBalance = balance; ViewBag.DisplayBalance = notstarted + balance; ViewBag.ValidBalance = balance > unapproved ? balance - unapproved : 0; ViewBag.LeaveTypes = WFUtilities.GetLeaveType(RouteData.Values["lang"] as string); } } ViewBag.StaffNo = this.Username; ViewBag.HasCoverDuties = WFEntities.WF_FlowGroups.FirstOrDefault(p => p.FlowTypeId == flowtypeid && p.StatusId > 0)?.HasCoverUsers; return(PartialView("FillFormValue", WFEntities.WF_FlowGroups.AsNoTracking().Include("WF_FlowPropertys").FirstOrDefault(p => p.FlowTypeId == flowtypeid && p.StatusId > 0))); }
public async Task <ActionResult> ChangePassword(string UserId, string Password, string NewPassword, string ConfirmPassword) { if (User.Identity.Name == "Admin") { ModelState.AddModelError("", (string)"Admin cannot change password"); return(View("ChangePassword", (object)UserId)); } if (NewPassword == ConfirmPassword) { LoginApiClient login = new LoginApiClient(); UserStaffInfo userInfo = WFUtilities.GetUserStaffInfo(UserId); RequestResult <BoolResult> res = await login.ChangeUserPasswordAsync(UserId, Password, NewPassword, userInfo.Country); if (!string.IsNullOrEmpty(res.ReturnValue.ret_msg)) { ModelState.AddModelError("", res.ReturnValue.ret_msg); return(View("ChangePassword", (object)UserId)); } return(RedirectToAction("LogOn")); } ModelState.AddModelError("", StringResource.PASSWORD_INCONSISTENT); return(View("ChangePassword", (object)UserId)); }
public (CreateFlowResult result, int flowCaseId) CreateFlowCase(CreateFlowCaseInfo info, int version = 0, int?baseId = null) { NextStepData nsd = GetNextStepApprovers(info.FlowId, info.Properties, CurrentUser); if ((nsd.EmployeeList.Count == 0 || nsd.EmployeeList.Count != info.Approver.Length) && nsd.NextSteps != null && nsd.NextSteps.Length > 0) { return(CreateFlowResult.InvalidSelectedApprovers, 0); } if (info.Approver != null) { for (int i = 0; i < info.Approver.Length; i++) { string userno = info.Approver[i]; if (nsd.EmployeeList[i].All(p => p.UserNo != userno)) { return(CreateFlowResult.InvalidSelectedApprovers, 0); } } } //没有step的也允许创建,并且创建的时候设置通过了审核 WF_FlowCases flowCase = new WF_FlowCases { Created = DateTime.UtcNow, Deadline = info.Deadline?.ToUniversalTime(), Department = info.Dep, LastUpdated = DateTime.UtcNow, LastChecked = DateTime.UtcNow, FlowId = info.FlowId, Subject = info.Subject, UserNo = CurrentUser, IsDissmissed = 0, IsRead = 0, StatusId = 1, Ver = version, BaseFlowCaseId = baseId, RelatedFlowCaseId = info.RelatedCaseId }; Entities.WF_FlowCases.Add(flowCase); AddCaseLog(CurrentUser, flowCase, CaseLogType.AppCreated); if (info.Attachments != null) { foreach (Attachment att in info.Attachments) { AddCaseAttachment(flowCase, att); } } AddFlowProperties(flowCase, info.Properties); AddCoverDuties(info.CoverDuties, flowCase); AddFinalNotifyUser(info.NotifyUsers, flowCase); bool hasSteps = true; if (nsd.NextSteps != null && nsd.NextSteps.Length > 0) { for (int i = 0; i < nsd.NextSteps.Length; i++) { WF_FlowSteps currentStep = nsd.NextSteps[i]; string currentUser = info.Approver[i]; if (currentStep.ApproverType == (int)ApproverType.Person && currentStep.UserNo.EqualsIgnoreCaseAndBlank(currentUser)) { continue; } UserStaffInfo userInfo = SearStaffInfo(currentUser); Entities.WF_CaseSteps.Add(new WF_CaseSteps { Created = DateTime.UtcNow, FlowStepId = currentStep.FlowStepId, Department = userInfo?.DepartmentName ?? string.Empty, UserNo = currentUser, WF_FlowCases = flowCase, LastUpdated = DateTime.UtcNow, StatusId = 1 }); } for (int i = 0; i < nsd.NextSteps.Length; i++) { AddCaseUserAction(flowCase, nsd.NextSteps[i].FlowStepId, info.Approver[i]); } } else { hasSteps = false; flowCase.Approved = DateTime.UtcNow; flowCase.IsDissmissed = 1; } if (!hasSteps) { WF_CaseNotifications notification = NotificationManager.CreateNotification(flowCase, null, null, NotificationTypes.AppFinishedApproved); NotificationManager.PushNotification(notification, CurrentUser, NotificationSources.ApproverApproved); } bool hasNotifyUsers = Entities.WF_ApplicantNotificationUsers.Local.Any(); if (hasNotifyUsers) { WF_CaseNotifications applicantNotification = NotificationManager.CreateNotification(flowCase, null, null, NotificationTypes.ApplicantNotification); PropertyInfo[] propertyInfos = info.Properties .Where(p => p.Value != null) .ToArray(); AddApplicantNotification(info.FlowId, applicantNotification, propertyInfos, CurrentUser); } try { Entities.SaveChanges(); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(CreateFlowResult.InvalidData, 0); } AutoApprove(flowCase.FlowCaseId, info.FlowId, info.Properties, CurrentUser); List <NextStepData> subsequents = GetSubsequentSteps(info.FlowId, info.Properties, CurrentUser); if (info.Approver != null && info.Approver.Length == 1 && subsequents != null && subsequents.Count > 0 && subsequents[0].EmployeeList != null) { Employee[] firstList = subsequents[0].EmployeeList[0]; string autoNextApprover = firstList[0].UserNo; bool shouldAutoApprove = false; foreach (var nextStepData in subsequents) { Employee employee = nextStepData.EmployeeList[0].First(); //因为只添加了只有一个审批者的步骤 if (info.Approver.Contains(employee.UserNo)) { shouldAutoApprove = true; break; } } if (shouldAutoApprove) { Approver approver = new Approver(Entities, info.Approver[0]); approver.Approve(flowCase.FlowCaseId, new string[] { autoNextApprover }); } } return(CreateFlowResult.Success, flowCase.FlowCaseId); }
public Employee[] FindUser() { if (UserType != null) { string country = PropertyValues.FirstOrDefault(p => p.Type == 9)?.Value ?? Consts.GetApiCountry();//#TODO string deptcode = PropertyValues.FirstOrDefault(p => p.Type == 11)?.Value ?? "%"; string depttype = PropertyValues.FirstOrDefault(p => p.Type == 12)?.Value ?? "%"; if (UserType == (int)ApproverType.PredefinedRole) { if ((CountryType.HasValue && CountryType.Value == 0) || (DeptType.HasValue && DeptType.Value == 0) || (DeptTypeSource.HasValue && DeptTypeSource.Value == 0)) { UserStaffInfo result = _userManager.SearchStaff(Applicant); if (result != null && CountryType == 0) { country = result.Country; } if (result != null && DeptType == 0) { deptcode = result.Department; } if (result != null && DeptTypeSource == 0) { depttype = result.DepartmentType; } } if (CountryType.HasValue && CountryType.Value == 2) { country = FixedCountry; } if (DeptType.HasValue && DeptType.Value == 2) { deptcode = FixedDept; } if (DeptTypeSource.HasValue && DeptTypeSource.Value == 2) { depttype = FixedDeptType; } string brand = ""; switch (BrandType) { case 1: brand = PropertyValues.FirstOrDefault(p => p.Type == 14)?.Value; break; case 2: brand = FixedBrand; break; } return(GetUserByRole(country, deptcode, UserRole.ToString(), depttype, brand)); } if (UserType == (int)ApproverType.PredefinedReportingLine) { var employees = GetManager(); if (UserNameByNo != null) { foreach (var employee in employees) { employee.Name = UserNameByNo(employee.UserNo) ?? employee.UserNo; } } return(employees); } if (UserType == (int)ApproverType.RoleCriteria) { if ((CountryType.HasValue && CountryType.Value == 0) || (DeptType.HasValue && DeptType.Value == 0)) { UserStaffInfo result = _userManager.SearchStaff(Applicant); if (result != null && CountryType == 0) { country = result.Country; } if (result != null && DeptType == 0) { deptcode = result.Department; } } if (CountryType.HasValue && CountryType.Value == 2) { country = FixedCountry; } if (DeptType.HasValue && DeptType.Value == 2) { deptcode = FixedDept; } return(GetUserByGrade(country, deptcode, depttype)); } } return(new[] { new Employee(SelectedUser, SelectedUsername) }); }
public bool Check(PropertyInfo[] values) { if (_otherProp.EqualsIgnoreCaseAndBlank("id")) { return(Compare(_userid, _value)); } if (_otherProp.EqualsIgnoreCaseAndBlank("grade")) { using (IUserManager um = Singleton <IUnityContainer> .Instance.Resolve <IUserManager>()) { UserStaffInfo staff = um.SearchStaff(_userid); if (staff == null) { return(false); } bool isNumberA = int.TryParse(staff.Grade.Substring(1), out var a); bool isNumberB = int.TryParse(_value, out var b); if (isNumberA && isNumberB) { if (_operator.ToLower().Equals("in") && !string.IsNullOrWhiteSpace(_maxValue)) { bool isNumberC = int.TryParse(_maxValue, out var c); if (isNumberC) { return(a <= b && a >= c); } return(false); } return(_operator.Equals("=") ? Compare(a, b) : Compare(b, a)); } return(false); } } if (_otherProp.EqualsIgnoreCaseAndBlank("approverno")) { using (IUserManager um = Singleton <IUnityContainer> .Instance.Resolve <IUserManager>()) { UserStaffInfo staff = um.SearchStaff(_userid); if (staff == null) { return(false); } return(Compare(staff.StaffId, _value)); } } PropertyInfo item = values.FirstOrDefault(p => p.Id == _property.FlowPropertyId); if (item == null) { return(false); } if (_property.PropertyType == 2) { return(int.TryParse(item.Value, out var a) && int.TryParse(_value, out var b) && Compare <int>(a, b)); } if (_property.PropertyType == 3) { return(DateTime.TryParse(item.Value, out var a) && DateTime.TryParse(_value, out var b) && Compare <DateTime>(a, b)); } if (_property.PropertyType == 4) { return(float.TryParse(item.Value, out var a) && float.TryParse(_value, out var b) && Compare <float>(a, b)); } if (_property.PropertyType == 5) { return(DateTime.TryParse(item.Value, out var a) && DateTime.TryParse(_value, out var b) && Compare <DateTime>(a.Date, b.Date)); } if (_property.PropertyType == 8) { return(TimeSpan.TryParse(item.Value, out var a) && TimeSpan.TryParse(_value, out var b) && Compare <TimeSpan>(a, b)); } return(Compare(item.Value.Trim(), _value.Trim())); }