public static JobTitleServiceAttributes Get(int jobTitleID, int languageID, int countryID)
        {
            var data = new JobTitleServiceAttributes();

            data.jobTitleID        = jobTitleID;
            data.languageID        = languageID;
            data.countryID         = countryID;
            data.serviceAttributes = ServiceAttribute.GetGroupedJobTitleAttributes(jobTitleID, languageID, countryID);
            data.experienceLevels  = ExperienceLevel.GetList(languageID, countryID);

            return(data);
        }
Ejemplo n.º 2
0
        public static PublicUserJobTitleServiceAttributes Get(int userID, int jobTitleID, int languageID, int countryID)
        {
            var data = new PublicUserJobTitleServiceAttributes();

            data.userID            = userID;
            data.jobTitleID        = jobTitleID;
            data.languageID        = languageID;
            data.countryID         = countryID;
            data.serviceAttributes = ServiceAttribute.GetGroupedUserJobTitleAttributes(jobTitleID, userID, languageID, countryID);
            var experienceID = UserJobTitleServiceAttributes.GetExperienceLevelID(userID, jobTitleID, languageID, countryID);

            data.experienceLevel = ExperienceLevel.GetItem(experienceID, languageID, countryID);

            return(data);
        }
        static public void Set(UserJobTitleServiceAttributes serviceAttributes)
        {
            // Validate
            // Get all attributes that applies (we avoid save selected attributes that does not apply
            // to the job title).
            var validAttributes        = ServiceAttribute.GetGroupedJobTitleAttributes(serviceAttributes.jobTitleID, serviceAttributes.languageID, serviceAttributes.countryID);
            var indexedValidAttributes = new Dictionary <int, HashSet <int> >();

            // Check that there is almost one value for required categories, or show error
            foreach (var attCat in validAttributes)
            {
                if (attCat.requiredInput && (
                        !serviceAttributes.serviceAttributes.ContainsKey(attCat.serviceAttributeCategoryID) ||
                        serviceAttributes.serviceAttributes[attCat.serviceAttributeCategoryID].Count == 0))
                {
                    throw new ValidationException(String.Format(requiredAttCatError, attCat.name), attCat.serviceAttributeCategoryID.ToString(), "serviceAttributes");
                }
                indexedValidAttributes.Add(attCat.serviceAttributeCategoryID, new HashSet <int>(attCat.serviceAttributes.Select(x => x.serviceAttributeID)));
            }

            // Save data
            using (var db = new LcDatabase())
            {
                // Transaction
                db.Execute("BEGIN TRANSACTION");

                // First, remove all current attributes, replaced by the new set
                db.Execute(sqlDelAllAttributes, serviceAttributes.userID, serviceAttributes.jobTitleID, serviceAttributes.languageID, serviceAttributes.countryID);

                // Add new ones, if they are valid
                foreach (var cat in serviceAttributes.serviceAttributes)
                {
                    if (indexedValidAttributes.ContainsKey(cat.Key))
                    {
                        foreach (var att in cat.Value)
                        {
                            if (indexedValidAttributes[cat.Key].Contains(att))
                            {
                                // Add to database
                                db.Execute(sqlInsertAttribute, serviceAttributes.userID, serviceAttributes.jobTitleID, cat.Key, att, serviceAttributes.languageID, serviceAttributes.countryID);
                            }
                            // else JUST DISCARD SILENTLY INVALID ATTID
                        }
                    }
                    // else JUST DISCARD SILENTLY INVALID CATID
                }

                // Register user proposed new attributes:
                foreach (var cat in serviceAttributes.proposedServiceAttributes)
                {
                    // Category must exists, even if the attribute is new.
                    if (indexedValidAttributes.ContainsKey(cat.Key))
                    {
                        foreach (var attName in cat.Value)
                        {
                            if (String.IsNullOrWhiteSpace(attName))
                            {
                                continue;
                            }

                            // Clean-up, preparation of the new name
                            var newAttName = attName.Capitalize().Replace(",", "");

                            // Register new attribute
                            int serviceAttributeID = db.QueryValue(sqlRegisterNewAttribute,
                                                                   serviceAttributes.languageID,
                                                                   serviceAttributes.countryID,
                                                                   null, // sourceID
                                                                   newAttName,
                                                                   null, // description
                                                                   serviceAttributes.jobTitleID,
                                                                   serviceAttributes.userID,
                                                                   false,  // Initially not approved
                                                                   cat.Key // categoryID
                                                                   );
                            // Set for the user:
                            db.Execute(sqlInsertAttribute, serviceAttributes.userID, serviceAttributes.jobTitleID,
                                       cat.Key, serviceAttributeID, serviceAttributes.languageID, serviceAttributes.countryID);
                        }
                    }
                }

                if (serviceAttributes.proposedServiceAttributes.Count > 0)
                {
                    LcMessaging.NotifyNewServiceAttributes(serviceAttributes.userID, serviceAttributes.jobTitleID, serviceAttributes.proposedServiceAttributes);
                }

                // Since ExperienceLevel is not a service category anymore else an independent table, we need
                // specific code to save its data.
                if (serviceAttributes.experienceLevelID > 0)
                {
                    db.Execute(sqlSetExpLevel, serviceAttributes.userID, serviceAttributes.jobTitleID, serviceAttributes.languageID, serviceAttributes.countryID, serviceAttributes.experienceLevelID);
                }
                else
                {
                    db.Execute(sqlDelExpLevel, serviceAttributes.userID, serviceAttributes.jobTitleID, serviceAttributes.languageID, serviceAttributes.countryID);
                }

                // Check alert
                db.Execute("EXEC TestAlertPositionServices @0, @1", serviceAttributes.userID, serviceAttributes.jobTitleID);

                // Ends transaction (very important for the delete-insert attributes part, but it guarantees that all or nothing):
                db.Execute("COMMIT TRANSACTION");
            }
        }