public static UserPositionActivation CheckUserPositionActivation(int userID, Dictionary <int, dynamic> positionsStatuses) { // Avoid cache before get updated data: CleanCacheGetUserPos(userID); var newStatuses = GetUserPositionsStatuses(userID); var posActivationList = new List <UserPositionActivation>(); var totalNumbers = LcData.GetUserAlertsNumbers(userID); foreach (var ps in newStatuses) { var rtn = new UserPositionActivation(userID); // Get alert numbers for this position or an empty numbers if there is no alerts actived for the position. var numbers = totalNumbers.ContainsKey(ps.Key) ? totalNumbers[ps.Key] : new LcData.UserAlertsNumbers(); rtn.NextAlert = numbers.NextAlert; // Check if is enabled if (ps.Value.StatusID == 1) { // By default, set as complete until other conditions change it: rtn.Status = UserPositionActivation.Statuses.Complete; if (ps.Value.StatusID != positionsStatuses[ps.Key].StatusID) { // It was enabled right now: rtn.Status = UserPositionActivation.Statuses.JustCompleted; rtn.Messages.Add(LcRessources.GetText("PositionActivationComplete", ps.Value.PositionSingular)); } // There are still non required alerts? must be showed as Enhance if (numbers.CountActiveAlerts > 0) { rtn.Status = UserPositionActivation.Statuses.Enhance; } } else if (ps.Value.StatusID == 2) { rtn.Status = UserPositionActivation.Statuses.InProgress; if (numbers.CountRequiredAlerts > 0) { // It is still incomplete, show progress rtn.Messages.Add(LcRessources.GetText("PositionActivationProgress", numbers.CountRequiredPassedAlerts, numbers.CountRequiredAlerts, ps.Value.PositionSingular) ); } } posActivationList.Add(rtn); } return(UserPositionActivation.Max(posActivationList)); }
public bool ValidateProviderData(PackageBaseData package, System.Web.WebPages.Html.ModelStateDictionary modelState) { var valid = true; PricingVariables provars = PricingVariables.FromPackageBaseData(package); foreach (var provar in provars) { if (provar.Value.Def.IsProviderVariable) { // Validation: Emit error if there is not a value or is not of the desired type if (String.IsNullOrWhiteSpace(Request[provar.Key + "-value"])) { modelState.AddError(provar.Key + "-value", LcRessources.RequiredField(provar.Value.Def.VariableLabel)); valid = false; } else if (!LcUtils.ValidateType(Request[provar.Key + "-value"], provar.Value.Def.DataType)) { modelState.AddError(provar.Key + "-value", LcRessources.InvalidFieldValue(provar.Value.Def.VariableLabel)); valid = false; } // NO Validation: Detect pricing variable 'hourly rate' to copy the value to the standard field on package // PricingVariableID:1 'hourly rate' for all positions and pricings. // We need to do this data change on validation because the 'save' part happen after the package being saved (for good reasons) if (provar.Value.PricingVariableID == 1) { package.PriceRate = Request[provar.Key + "-value"].AsDecimal(); package.PriceRateUnit = "hour"; } // Validation: Check the optional variable value properties (number, min, max) if (!String.IsNullOrWhiteSpace(Request[provar.Key + "-numberincluded"]) && !Request[provar.Key + "-numberincluded"].IsDecimal()) { modelState.AddError(provar.Key + "-numberincluded", String.Format("Invalid number for included '{0}'", provar.Value.Def.VariableNameSingular)); valid = false; } if (!String.IsNullOrWhiteSpace(Request[provar.Key + "-minnumberallowed"]) && !Request[provar.Key + "-minnumberallowed"].IsDecimal()) { modelState.AddError(provar.Key + "-minnumberallowed", String.Format("Invalid number for '{0}'", provar.Value.Def.MinNumberAllowedLabel)); valid = false; } if (!String.IsNullOrWhiteSpace(Request[provar.Key + "-maxnumberallowed"]) && !Request[provar.Key + "-maxnumberallowed"].IsDecimal()) { modelState.AddError(provar.Key + "-maxnumberallowed", String.Format("Invalid number for '{0}'", provar.Value.Def.MaxNumberAllowedLabel)); valid = false; } } } return(valid); }
public static Dictionary <int, Dictionary <string, object> > GetServiceCatsAndItsAttributes(int positionId, string filters = null, int userId = 0) { var rcats = new Dictionary <int, Dictionary <string, object> >(); var catsFilter = new List <int>(); // Set if the catsFilter is the list of cats to be excluded from the total (value: true) // or is a list of unique cats to be returned (value: false) bool excludeCats = false; // This bool config set that only attributes related to the userId must be returned (query field 'UserChecked' == True) bool onlyUserChecked = false; bool onlyBookingServices = false; List <string> filterList = new List <string>(); // Reading filters: if (filters != null) { filterList.AddRange(filters.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); } foreach (string filter in filterList) { switch (filter) { case "provider-services-without-virtual-cats": case "provider-services": //catsFilter.AddRange(new int[]{1, 2, 3, 4, 5, 7}); //catsFilter.AddRange(new int[]{1, 2, 4, 5, 7}); excludeCats = false; break; case "without-special-cats": catsFilter = SpecialServicesAttCats; excludeCats = true; break; case "only-special-cats": catsFilter = SpecialServicesAttCats; excludeCats = false; break; case "only-user-checked": onlyUserChecked = true; break; case "booking-services": onlyBookingServices = true; break; } } var sqlcat = "exec GetServiceAttributeCategories @0, @1, @2, @3"; var sqlattribute = "exec GetServiceAttributes @0, @1, @2, @3, @4, @5"; using (var db = Database.Open("sqlloco")) { var catrow = db.Query(sqlcat, positionId, LcData.GetCurrentLanguageID(), LcData.GetCurrentCountryID(), onlyBookingServices); // Iterate the categories foreach (var cat in catrow) { // Apply filtering, if there are if (catsFilter.Count > 0 && (excludeCats && catsFilter.Contains(cat.ServiceAttributeCategoryID) || !excludeCats && !catsFilter.Contains(cat.ServiceAttributeCategoryID) )) { continue; } // Copy data to a new structure var rcat = new Dictionary <string, object>() { { "ServiceAttributeCategoryID", cat.ServiceAttributeCategoryID }, { "ServiceAttributeCategoryName", cat.ServiceCat }, { "ServiceAttributeCategoryDescription", cat.ServiceAttributeCategoryDescription }, { "RequiredInput", cat.RequiredInput }, { "SideBarCategory", cat.SideBarCategory } }; // Getting attributes of the category rcat["ServiceAttributes"] = db.Query(sqlattribute, positionId, cat.ServiceAttributeCategoryID, LcData.GetCurrentLanguageID(), LcData.GetCurrentCountryID(), (userId == 0 ? null : (object)userId), onlyUserChecked); rcats.Add(cat.ServiceAttributeCategoryID, rcat); } /* SPECIAL CASES */ if (filterList.Contains("provider-services") || filterList.Contains("only-special-cats")) { // Adding the extra tables Language Levels and Experience Levels as 'virtual' categories, using the same // fields name to be easy to implement // Returning a 'virtual' language levels category var rcat = new Dictionary <string, object>() { { "ServiceAttributeCategoryID", ServiceAttCatIDLanguageLevel }, { "ServiceAttributeCategoryName", LcRessources.GetText("Language Level") }, { "ServiceAttributeCategoryDescription", LcRessources.GetText("Language Level Description") }, { "RequiredInput", false }, { "SideBarCategory", true } }; var levelsIndex = new Dictionary <int, int>(); var langlevels = new List <object>(); foreach (var level in LcData.GetLanguageLevels()) { langlevels.Add(new Dictionary <string, object> { { "ServiceAttributeDescription", level.LanguageLevelDescription }, { "ServiceAttributeID", level.LanguageLevelID }, { "ServiceAttribute", level.LanguageLevelName }, { "UserChecked", false } }); levelsIndex.Add(level.LanguageLevelID, langlevels.Count - 1); } rcat["ServiceAttributes"] = langlevels; if (userId > 0) { rcat["LevelsIndex"] = levelsIndex; rcat["UserSelectedLevels"] = LcData.GetUserLanguageLevels(userId, positionId); } rcats[ServiceAttCatIDLanguageLevel] = rcat; // Returning a 'virtual' experience levels category rcat = new Dictionary <string, object>() { { "ServiceAttributeCategoryID", ServiceAttCatIDExperienceLevel }, { "ServiceAttributeCategoryName", LcRessources.GetText("Experience Level") }, { "ServiceAttributeCategoryDescription", LcRessources.GetText("Experience Level Description") }, { "RequiredInput", false }, { "SideBarCategory", true } }; var explevels = new List <object>(); foreach (var level in GetExperienceLevels(userId, positionId)) { if (!onlyUserChecked || level.UserChecked) { explevels.Add(new Dictionary <string, object> { { "ServiceAttributeDescription", level.ExperienceLevelDescription }, { "ServiceAttributeID", level.ExperienceLevelID }, { "ServiceAttribute", level.ExperienceLevelName }, { "UserChecked", level.UserChecked } }); } } rcat["ServiceAttributes"] = explevels; rcats[ServiceAttCatIDExperienceLevel] = rcat; } } return(rcats); }