public static BranchUser UpdateBranchUserRole(ApplicationDbContext db, Guid branchUserId, UserRoleEnum userRole) { BranchUser branchUser = GetBranchUser(db, branchUserId); //if user role changing FROM or TO Super/Admin user then set appUser flags accordingly if (userRole == UserRoleEnum.SuperUser) { AppUserHelpers.UpdateRoleFlags(db, branchUser.UserId, true, false); } if (userRole == UserRoleEnum.Admin) { AppUserHelpers.UpdateRoleFlags(db, branchUser.UserId, false, true); } //if role changes to Admin/Super user from anything else then add all company branches to user and activate if required if ((userRole == UserRoleEnum.SuperUser || userRole == UserRoleEnum.Admin) && (branchUser.UserRole != UserRoleEnum.SuperUser && branchUser.UserRole != UserRoleEnum.Admin)) { BranchUserHelpers.CreateBranchUserAdminRolesForUserForAllBranches(db, branchUser, userRole); } else { branchUser.UserRole = userRole; } branchUser.UserRole = userRole; db.Entry(branchUser).State = EntityState.Modified; db.SaveChanges(); return(branchUser); }
public static AvailableListing CreateAvailableListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?availableFrom, DateTime?availableTo, ItemConditionEnum itemCondition, DateTime?displayUntilDate, DateTime?sellByDate, DateTime?useByDate, bool?deliveryAvailable, ItemRequiredListingStatusEnum listingStatus) { BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user); Branch branch = BranchHelpers.GetBranch(db, branchUser.BranchId); AvailableListing AvailableListing = new AvailableListing() { ListingId = Guid.NewGuid(), ItemDescription = itemDescription, ItemCategory = itemCategory, ItemType = itemType, QuantityRequired = quantityRequired, QuantityFulfilled = 0, QuantityOutstanding = quantityRequired, UoM = uom, AvailableFrom = availableFrom, AvailableTo = availableTo, ItemCondition = itemCondition, DisplayUntilDate = displayUntilDate, SellByDate = sellByDate, UseByDate = useByDate, DeliveryAvailable = deliveryAvailable ?? false, ListingBranchPostcode = branch.AddressPostcode, ListingOriginatorAppUserId = branchUser.UserId, ListingOriginatorBranchId = branchUser.BranchId, ListingOriginatorCompanyId = branchUser.CompanyId, ListingOriginatorDateTime = DateTime.Now, ListingStatus = ItemRequiredListingStatusEnum.Open }; db.AvailableListings.Add(AvailableListing); db.SaveChanges(); return(AvailableListing); }
public static AppUser UpdateAppUserFromAppUserEditView(ApplicationDbContext db, AppUserEditView view) { //Update AppUser AppUser appUser = GetAppUser(db, view.AppUserId); appUser.FirstName = view.FirstName; appUser.LastName = view.LastName; appUser.EntityStatus = view.EntityStatus; appUser.PrivacyLevel = view.PrivacyLevel; if (view.SelectedBranchId != null) { appUser.CurrentBranchId = view.SelectedBranchId.Value; } db.Entry(appUser).State = EntityState.Modified; db.SaveChanges(); //Update BranchUser (Role) BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId); BranchUserHelpers.UpdateBranchUserRole(db, branchUser.BranchUserId, view.UserRole); //Update UserSettings AppUserSettingsHelpers.UpdateUserSettingsFromAppUserEditView(db, view); return(appUser); }
public static void CreateBranchUserAdminRolesForUserForAllBranches(ApplicationDbContext db, BranchUser branchUser, UserRoleEnum userRole) { List <Branch> companyBranches = BranchHelpers.GetBranchesForCompany(db, branchUser.CompanyId); foreach (Branch branch in companyBranches) { BranchUser thisBranchUser = BranchUserHelpers.GetBranchUser(db, branchUser.UserId, branch.BranchId, branch.CompanyId); //Update if required else create new if missing if (thisBranchUser != null) { //if this branchuser is having the status changed then just check any outstanding actions and remove if (userRole != thisBranchUser.UserRole) { thisBranchUser.UserRole = userRole; thisBranchUser.EntityStatus = EntityStatusEnum.Active; db.Entry(branchUser).State = EntityState.Modified; db.SaveChanges(); } } else { BranchUserHelpers.CreateBranchUser(db, branchUser.UserId, branch.BranchId, branch.CompanyId, userRole, EntityStatusEnum.Active); } } }
public static RequirementListing CreateRequirementListing(ApplicationDbContext db, IPrincipal user, string itemDescription, ItemCategoryEnum itemCategory, ItemTypeEnum itemType, decimal quantityRequired, string uom, DateTime?requiredFrom, DateTime?requiredTo, bool acceptDamagedItems, bool acceptOutOfDateItems, bool collectionAvailable, ItemRequiredListingStatusEnum listingStatus, Guid?selectedCampaignId) { BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user); Branch branch = BranchHelpers.GetBranch(db, branchUser.BranchId); RequirementListing requirementListing = new RequirementListing() { ListingId = Guid.NewGuid(), ItemDescription = itemDescription, ItemCategory = itemCategory, ItemType = itemType, QuantityRequired = quantityRequired, QuantityFulfilled = 0, QuantityOutstanding = quantityRequired, UoM = uom, RequiredFrom = requiredFrom, RequiredTo = requiredTo, AcceptDamagedItems = acceptDamagedItems, AcceptOutOfDateItems = acceptOutOfDateItems, CollectionAvailable = collectionAvailable, ListingBranchPostcode = branch.AddressPostcode, ListingOriginatorAppUserId = branchUser.UserId, ListingOriginatorBranchId = branchUser.BranchId, ListingOriginatorCompanyId = branchUser.CompanyId, ListingOriginatorDateTime = DateTime.Now, ListingStatus = ItemRequiredListingStatusEnum.Open, CampaignId = selectedCampaignId }; db.RequirementListings.Add(requirementListing); db.SaveChanges(); return(requirementListing); }
public static void CreateBranchUserAdminRolesForUserForAllBranches(BranchUser branchUser, UserRoleEnum userRole) { ApplicationDbContext db = new ApplicationDbContext(); CreateBranchUserAdminRolesForUserForAllBranches(db, branchUser, userRole); db.Dispose(); }
public static Company GetCompanyForUser(ApplicationDbContext db, AppUser appUser) { BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId); Company company = GetCompany(db, branchUser.CompanyId); return(company); }
public static Offer CreateOfferForRequirement(ApplicationDbContext db, IPrincipal user, RequirementListing requirementListing, decimal offerQuantity) { BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user); Offer offer = new Offer() { OfferId = Guid.NewGuid(), ListingId = requirementListing.ListingId, ListingType = ListingTypeEnum.Requirement, OfferStatus = OfferStatusEnum.New, CurrentOfferQuantity = offerQuantity, OfferOriginatorAppUserId = branchUser.UserId, OfferOriginatorBranchId = branchUser.BranchId, OfferOriginatorCompanyId = branchUser.CompanyId, OfferOriginatorDateTime = DateTime.Now, ListingOriginatorAppUserId = requirementListing.ListingOriginatorAppUserId, ListingOriginatorBranchId = requirementListing.ListingOriginatorBranchId, ListingOriginatorCompanyId = requirementListing.ListingOriginatorCompanyId, ListingOriginatorDateTime = requirementListing.ListingOriginatorDateTime }; db.Offers.Add(offer); db.SaveChanges(); return(offer); }
public BranchUser GetSingle(Int32 Id) { BranchUser obj = new BranchUser(); try { string query = "select * from branch_users where ID = " + Id + ""; SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); DataTable dt = new DataTable(); SqlDataAdapter dA = new SqlDataAdapter(cmd); dA.Fill(dt); dA.Dispose(); obj = (from x in dt.AsEnumerable() select new BranchUser { Id = x.Field <Int32>("id"), BranchId = x.Field <Int32>("branch_id"), UserId = x.Field <Int32>("user_id"), CreatedBy = x.Field <Int32>("created_by"), CreatedDate = x.Field <DateTime>("created_date"), UpdatedBy = x.Field <Int32?>("updated_by") == null ? 0 : x.Field <Int32>("updated_by"), UpdatedDate = x.Field <DateTime?>("updated_date"), Status = x.Field <Int32>("status"), }).ToList().FirstOrDefault(); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public async Task AddUserAsyn(BranchUserModel branchUserModel, string agencyCode) { Check.ArgumentNotNull(nameof(branchUserModel), branchUserModel); var user = await _iDMAppService.FindUserProfileByUserNameAsync(branchUserModel.UserName); if (user != null) { _branchServiceDomain.AssignBranchUserExist(branchUserModel.BranchId, branchUserModel.RoleName, user); } List <IDMRolesModel> roles = _iDMAppService.GetIDMRoles(); IDMRolesModel iDMRolesModel = roles.FirstOrDefault(r => r.Name == branchUserModel.RoleName); branchUserModel.RoleName = iDMRolesModel.Name; branchUserModel.RoleArName = iDMRolesModel.NormalizedName; Enums.UserRole userType = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName, true); UserProfile userProfile = new UserProfile(); if (user == null) { userProfile = await _iDMAppService.GetUserProfileByEmployeeId(branchUserModel.UserName, agencyCode, userType); Check.ArgumentNotNull(nameof(userProfile), userProfile); await _genericCommandRepository.CreateAsync(userProfile); branchUserModel.UserId = userProfile.Id; } else { var defaultSettingsForUserType = await _notificationAppService.GetDefaultSettingByUserType(userType); if (user.NotificationSetting.Count(x => x.UserRoleId == (int)userType) < defaultSettingsForUserType.Count) { await _branchServiceDomain.CheckUserExist(user.Id, branchUserModel.BranchId, branchUserModel.RoleName); user.AddNotificationSettings(defaultSettingsForUserType); _genericCommandRepository.Update(user); } branchUserModel.UserId = user.Id; } var branchUser = new BranchUser(branchUserModel.BranchId, branchUserModel.UserId, (int)((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName)), branchUserModel.RelatedAgencyCode, branchUserModel.EstimatedValueFrom, branchUserModel.EstimatedValueTo); await _genericCommandRepository.CreateAsync(branchUser); await _genericCommandRepository.SaveAsync(); if (user != null) { if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile); } } else { if (!string.IsNullOrEmpty(userProfile.Email) || !string.IsNullOrEmpty(userProfile.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(userProfile.Id, userProfile.Email, userProfile.Mobile); } } }
//Returns the current branch/company/appuser for the user sent public static BranchUser GetBranchUserCurrentForUser(IPrincipal user) { ApplicationDbContext db = new ApplicationDbContext(); BranchUser branchUser = GetBranchUserCurrentForUser(db, user); db.Dispose(); return(branchUser); }
public static BranchUser GetBranchUser(ApplicationDbContext db, Guid appUserId, Guid branchId, Guid companyId) { BranchUser branchUser = (from b in db.BranchUsers where (b.BranchId == branchId && b.UserId == appUserId && b.CompanyId == companyId) select b).FirstOrDefault(); return(branchUser); }
public static BranchUser GetBranchUser(Guid appUserId, Guid branchId, Guid companyId) { ApplicationDbContext db = new ApplicationDbContext(); BranchUser branchUser = GetBranchUser(db, appUserId, branchId, companyId); db.Dispose(); return(branchUser); }
public static BranchUser UpdateBranchUserStatus(BranchUser branchUser, EntityStatusEnum newEntityStatus, Guid appUserId) { ApplicationDbContext db = new ApplicationDbContext(); BranchUser updateBranchUser = UpdateBranchUserStatus(db, branchUser, newEntityStatus, appUserId); db.Dispose(); return(updateBranchUser); }
public static BranchUser CreateBranchUser(Guid userId, Guid branchId, Guid companyId, UserRoleEnum userRole, EntityStatusEnum entityStatus) { ApplicationDbContext db = new ApplicationDbContext(); BranchUser branchUser = CreateBranchUser(db, userId, branchId, companyId, userRole, entityStatus); db.Dispose(); return(branchUser); }
public static BranchUser UpdateBranchUserRole(Guid branchUserId, UserRoleEnum userRole) { ApplicationDbContext db = new ApplicationDbContext(); BranchUser updateBranchUser = UpdateBranchUserRole(db, branchUserId, userRole); db.Dispose(); return(updateBranchUser); }
public static List <AvailableListing> GetAllAvailableListingsForBranchUser(BranchUser branchUser) { ApplicationDbContext db = new ApplicationDbContext(); List <AvailableListing> list = GetAllAvailableListingsForBranchUser(db, branchUser); db.Dispose(); return(list); }
public static List <Campaign> GetAllCampaignsForBranchUser(BranchUser branchUser) { ApplicationDbContext db = new ApplicationDbContext(); List <Campaign> list = GetAllCampaignsForBranchUser(db, branchUser); db.Dispose(); return(list); }
public static List <Offer> GetAllOffersForBranchUser(BranchUser branchUser) { ApplicationDbContext db = new ApplicationDbContext(); List <Offer> list = GetAllOffersForBranchUser(db, branchUser); db.Dispose(); return(list); }
public async Task <ActionResult> Create(AppUserView model) { if (ModelState.IsValid) { //initialise the task creation flags bool createUserOnHoldTask = false; //Retrieve Branch Branch branch = BranchHelpers.GetBranch(db, model.SelectedBranchId.Value); //Create a new AppUser then write here AppUser appUser = AppUserHelpers.CreateAppUser(model.FirstName, model.LastName, branch.BranchId, model.EntityStatus, model.Email, model.PrivacyLevel, model.UserRole); BranchUser branchUser = null; var user = new ApplicationUser { UserName = model.Email, Email = model.Email, AppUserId = appUser.AppUserId, FullName = model.FirstName + " " + model.LastName, CurrentUserRole = model.UserRole }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //set on-hold task flag if (model.EntityStatus == EntityStatusEnum.OnHold) { createUserOnHoldTask = true; } //Now Update related entities //BranchUser - set the status as ACTIVE as the link is active even though the entities linked are not. branchUser = BranchUserHelpers.CreateBranchUser(appUser.AppUserId, branch.BranchId, branch.CompanyId, model.UserRole, EntityStatusEnum.Active); //Task creation if (createUserOnHoldTask) { UserTaskHelpers.CreateUserTask(TaskTypeEnum.UserOnHold, "New user on hold, awaiting administrator/manager activation", appUser.AppUserId, appUser.AppUserId, EntityStatusEnum.Active); } return(RedirectToAction("UserAdmin", "Admin")); } //Delete the appUser account as this has not gone through AppUserHelpers.DeleteAppUser(appUser.AppUserId); AddErrors(result); } // If we got this far, something failed, redisplay form - set up the drop downs dependant on what was there originally from the model Branch userBranch = BranchHelpers.GetCurrentBranchForUser(AppUserHelpers.GetGuidFromUserGetAppUserId(User.Identity.GetAppUserId())); //DropDown ViewBag.BranchList = ControlHelpers.AllBranchesForCompanyListDropDown(userBranch.CompanyId, userBranch.BranchId); ViewBag.UserRoleList = ControlHelpers.UserRoleEnumListDropDown(); ViewBag.EntityStatusList = ControlHelpers.EntityStatusEnumListDropDown(); return(View(model)); }
public void ShouldAssignBranchUserExist(int branchId, string roleName) { UserProfile userProfile = new UserProfile(1, "1087287072", "hamed", "0533286913", "*****@*****.**", null); BranchUser branchUser = new BranchUser(1, 1, 1, ""); userProfile.BranchUsers = new System.Collections.Generic.List <BranchUser>(); userProfile.BranchUsers.Add(branchUser); _sutBranchServiceDomain.AssignBranchUserExist(branchId, roleName, userProfile); Assert.IsType <bool>(true); }
public BranchUser ReturnBranchUserDefaults() { BranchUser generalBranchUser = new BranchUser(_branchId, _userProfileId, _userRoleId, _relatedAgencyCode, _estimatedValueFrom, _estimatedValueTo); generalBranchUser.CreateBranchForTest(new Branch(_agencyCode, "testbranch", new List <BranchAddress> ())); generalBranchUser.CreateUserProfile(); generalBranchUser.CreateUserRoleForTest(); generalBranchUser.UserProfile.Update("hamed", "1087287072", "*****@*****.**", "0533286913"); return(generalBranchUser); }
public static BranchUser UpdateBranchUserStatus(ApplicationDbContext db, BranchUser branchUser, EntityStatusEnum newEntityStatus, Guid appUserId) { branchUser.PreviousEntityStatus = branchUser.EntityStatus; branchUser.EntityStatus = newEntityStatus; branchUser.EntityStatusChangeBy = appUserId; branchUser.EntityStatusChangeDate = DateTime.Now; db.Entry(branchUser).State = EntityState.Modified; db.SaveChanges(); return(branchUser); }
public BranchUser UpdateData(BranchUser obj) { try { obj = IBranchUserRepo.UpdateData(obj); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public void ShouldAssignBranchUserExistThrowException(int branchId, string roleName) { UserProfile userProfile = new UserProfile(1, "1087287072", "hamed", "0533286913", "*****@*****.**", null); BranchUser branchUser = new BranchUser(5, 1, 25, ""); userProfile.BranchUsers = new System.Collections.Generic.List <BranchUser>(); userProfile.BranchUsers.Add(branchUser); Action action = () => { _sutBranchServiceDomain.AssignBranchUserExist(branchId, roleName, userProfile); }; var exception = action.ShouldThrow(typeof(BusinessRuleException)); exception.Message.ShouldBe(Resources.CommitteeResources.ErrorMessages.UserAlreadyExist); }
public BranchUser DeleteData(Int32 Id) { BranchUser obj = new BranchUser(); try { obj = IBranchUserRepo.DeleteData(Id); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
/// <summary> /// Adds all Admin users for the company of the new branch to the new branch /// </summary> /// <param name="db"></param> /// <param name="branchId">new branch id</param> public static void CreateBranchAdminUsersForNewBranch(ApplicationDbContext db, Branch branch, UserRoleEnum role) { List <AppUser> adminAppUsersForCompany = AppUserHelpers.GetAdminAppUsersForCompany(db, branch.CompanyId); foreach (AppUser adminUser in adminAppUsersForCompany) { BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, adminUser.AppUserId, branch.BranchId, branch.CompanyId); //Only add if not already there if (branchUser == null) { BranchUserHelpers.CreateBranchUser(db, adminUser.AppUserId, branch.BranchId, branch.CompanyId, role, EntityStatusEnum.Active); } } }
public BranchUser UpdateData(BranchUser obj) { try { string query = obj.ObjectToQuery <BranchUser>("update"); SqlCommand cmd = new SqlCommand(query, mySQLDBConnect.connection); mySQLDBConnect.OpenConnection(); cmd.ExecuteNonQuery(); mySQLDBConnect.CloseConnection(); } catch (Exception ex) { Console.Write(ex.ToString()); } return(obj); }
public async Task AddUserToBranchAsyn(BranchUserAssignModel branchUserModel, string agencyCode) { Check.ArgumentNotNull(nameof(branchUserModel), branchUserModel); var user = await _iDMAppService.FindUserProfileByUserNameAsync(branchUserModel.NationalIdString); Enums.UserRole userRole = ((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName)); if (user == null) { ManageUsersAssignationModel emp = await _iDMAppService.GetMonafastatEmployeeDetailById(agencyCode, branchUserModel.NationalIdString, ""); UserProfile userProfile = new UserProfile(emp.userId, emp.nationalId, emp.fullName, emp.mobileNumber, emp.email, await _notificationAppService.GetDefaultSettingByUserType(userRole)); Check.ArgumentNotNull(nameof(userProfile), userProfile); await _genericCommandRepository.CreateAsync(userProfile); branchUserModel.UserId = userProfile.Id; } else { if (!user.NotificationSetting.Any(x => x.UserRoleId == (int)userRole)) { await _branchServiceDomain.CheckUserExist(user.Id, branchUserModel.BranchId, branchUserModel.RoleName); user.AddNotificationSettings(await _notificationAppService.GetDefaultSettingByUserType(userRole)); _genericCommandRepository.Update(user); } branchUserModel.UserId = user.Id; } var branchUser = new BranchUser(branchUserModel.BranchId, branchUserModel.UserId.Value, (int)userRole, branchUserModel.RelatedAgencyCode, branchUserModel.EstimatedValueFrom, branchUserModel.EstimatedValueTo); await _genericCommandRepository.CreateAsync(branchUser); await _genericCommandRepository.SaveAsync(); if (user == null) { if (!string.IsNullOrEmpty(branchUser.UserProfile.Email) || !string.IsNullOrEmpty(branchUser.UserProfile.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(branchUser.UserProfile.Id, branchUser.UserProfile.Email, branchUser.UserProfile.Mobile); } } else { if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile)) { await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile); } } }
public static Offer UpdateCounterOffer(ApplicationDbContext db, IPrincipal user, Offer offer, decimal offerQuantity) { BranchUser branchUser = BranchUserHelpers.GetBranchUserCurrentForUser(db, user); offer.CounterOfferQuantity = offerQuantity; offer.PreviousOfferQuantity = offer.CurrentOfferQuantity; offer.CurrentOfferQuantity = 0; offer.LastCounterOfferOriginatorAppUserId = branchUser.UserId; offer.LastCounterOfferOriginatorBranchId = branchUser.BranchId; offer.LastCounterOfferOriginatorCompanyId = branchUser.CompanyId; offer.LastCounterOfferOriginatorDateTime = DateTime.Now; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); return(offer); }