private void UpSertStoreCats(string selectedItems, StoreNotExpired storeToUpdate) { if (storeToUpdate.Categories == null) { storeToUpdate.Categories = new List <Category>(); } var selectedCategoriesHS = !String.IsNullOrWhiteSpace(selectedItems) ? new HashSet <int>(selectedItems.Split(new char[] { ',' }) .Take(ITTConfig.MaxCategoryTagsLimit) .Select(u => int.Parse(u))) : new HashSet <int>(); var ProductCategories = storeToUpdate.Categories != null ? new HashSet <int>(storeToUpdate.Categories.Select(c => c.catID)) : new HashSet <int>(); IEnumerable <Category> catsToDelet = ProductCategories.Except(selectedCategoriesHS).Select(t => unitOfWork.CategoryRepository.GetByID(t)).ToList(); IEnumerable <Category> catsToInsert = selectedCategoriesHS.Except(ProductCategories).Select(t => unitOfWork.CategoryRepository.GetByID(t)).ToList(); foreach (var catToDel in catsToDelet) { storeToUpdate.Categories.Remove(catToDel); } foreach (var catToInsert in catsToInsert) { storeToUpdate.Categories.Add(catToInsert); } }
public ActionResult RequestAudit(PlanToApprove planRequestToApprove) { NullChecker.NullCheck(new object[] { planRequestToApprove.req }); if (ModelState.IsValid) { var planToApprove = unitOfWork.PlanRequetRepository .GetByID(EncryptionHelper.Unprotect(planRequestToApprove.req)); if (planToApprove.payment == null) { return(new RedirectToNotFound()); } if (planRequestToApprove.approve && planRequestToApprove.plantype == PlanType.Company) { if (planToApprove is RequestForNew) { var New = planToApprove as RequestForNew; CompanyNotExpired newCompany = new CompanyNotExpired(); if (planToApprove.plan == "Imperial") { newCompany = new Imperial(); } else if (planToApprove.plan == "Luxury") { newCompany = new Luxury(); } else if (planToApprove.plan == "HighClass") { newCompany = new HighClass(); } else { return(RedirectToAction("AllRequests")); } planToApprove.payment.payAcceptDate = DateTime.UtcNow; newCompany.regCode = (long)New.regCode; newCompany.coName = New.name; newCompany.coNameEN = New.name; newCompany.about = New.about; newCompany.aboutEN = New.about; newCompany.address = New.address; newCompany.addressEN = New.address; newCompany.email = New.Email; newCompany.phoneNo = (long)New.phoneNo; newCompany.stateID = New.stateID; newCompany.InsertionDate = DateTime.UtcNow; newCompany.registerDate = DateTime.UtcNow; newCompany.Admins = new List <ActiveUser>(); newCompany.Admins.Add(planToApprove.requesterUser); newCompany.Followers = new List <Following>(); newCompany.Followers.Add(new Following { FollowerUser = planToApprove.requesterUser, followDate = DateTime.UtcNow }); Setting newSetting = new Setting(); newCompany.Setting = newSetting; unitOfWork.NotExpiredCompanyRepository.Insert(newCompany); planToApprove.approve = true; unitOfWork.Save(); if (!Roles.IsUserInRole(planToApprove.requesterUser.UserName, "CoAdmin")) { Roles.AddUserToRole(planToApprove.requesterUser.UserName, "CoAdmin"); } return(RedirectToAction("AllRequests")); } else if (planToApprove is RevivalRequest) { var New = planToApprove as RevivalRequest; New.approve = true; DateTime lastPayement = unitOfWork.RevivalPlanRequestRepository.Get(r => r.coID == New.coID).Max(c => c.payment.payDate); New.payment.payDate = lastPayement.AddDays(365); unitOfWork.RevivalPlanRequestRepository.Update(New); unitOfWork.CompanyPlanChange((int)New.coID, New.plan); unitOfWork.Save(); return(RedirectToAction("AllRequests")); } return(new RedirectToError()); } else if (planRequestToApprove.approve && planRequestToApprove.plantype == PlanType.Store) { if (planToApprove is RequestForNew) { var New = planToApprove as RequestForNew; StoreNotExpired newStore = new StoreNotExpired(); if (planToApprove.plan == "GroundFloor") { newStore = new GroundFloor(); } else if (planToApprove.plan == "FirstFloor") { newStore = new FirstFloor(); } else if (planToApprove.plan == "SecondFloor") { newStore = new SecondFloor(); } else { return(RedirectToAction("AllRequests")); } planToApprove.payment.payAcceptDate = DateTime.UtcNow; newStore.regCode = New.regCode; newStore.storeName = New.name; newStore.storeNameEN = New.name; newStore.about = New.about; newStore.aboutEN = New.about; newStore.address = New.address; newStore.addressEN = New.address; newStore.email = New.Email; newStore.phoneNo = (long)New.phoneNo; newStore.stateID = New.stateID; newStore.registerDate = DateTime.Now.ToLocalTime(); newStore.Admins = new List <ActiveUser>(); newStore.Admins.Add(planToApprove.requesterUser); newStore.Followers = new List <Following>(); newStore.Followers.Add(new Following { FollowerUser = planToApprove.requesterUser, followDate = DateTime.UtcNow }); Setting newSetting = new Setting(); newStore.Setting = newSetting; unitOfWork.StoreNotExpiredRepository.Insert(newStore); planToApprove.approve = true; unitOfWork.Save(); if (!Roles.IsUserInRole(planToApprove.requesterUser.UserName, "StAdmin")) { Roles.AddUserToRole(planToApprove.requesterUser.UserName, "StAdmin"); } return(RedirectToAction("AllRequests")); } else if (planToApprove is RevivalRequest) { var New = planToApprove as RevivalRequest; New.approve = true; DateTime lastPayement = unitOfWork.RevivalPlanRequestRepository.Get(r => r.storeID == New.storeID).Max(c => c.payment.payDate); New.payment.payDate = lastPayement.AddDays(365); unitOfWork.RevivalPlanRequestRepository.Update(New); unitOfWork.StorePlanChange((int)New.storeID, New.plan); unitOfWork.Save(); return(RedirectToAction("AllRequests")); } return(new RedirectToError()); } else if (planRequestToApprove.approve && planRequestToApprove.plantype == PlanType.User) { if (planToApprove is RevivalRequest) { var New = planToApprove as RevivalRequest; UserProfile newUser = new UserProfile(); if (planToApprove.plan.ToLower() == "Professional") { newUser = new Professional(); } else if (planToApprove.plan.ToLower() == "Premium") { newUser = new Premium(); } else if (planToApprove.plan.ToLower() == "Basic") { newUser = new Basic(); } else { return(RedirectToAction("AllRequests")); } New.approve = true; DateTime lastPayement = unitOfWork.RevivalPlanRequestRepository.Get(r => r.userID == New.userID).Max(c => c.payment.payDate); New.payment.payDate = lastPayement.AddDays(365); unitOfWork.RevivalPlanRequestRepository.Update(New); unitOfWork.UserPlanChange((int)New.userID, New.plan); planToApprove.approve = true; unitOfWork.Save(); return(RedirectToAction("AllRequests")); } else { return(new RedirectToError()); } } } return(new RedirectToError()); }