Example #1
0
        /// <summary>
        /// Opdaterer F*g/Kursus forløb hørende til ét uddannelsesforløb specificeret ved id, UserName og
        /// Password.
        /// </summary>
        /// <remarks>
        /// UserName og Password skal være gemt i Web API'ets database for at være gyldige.
        /// </remarks>
        /// <param name="json_Object">json_Objekt er et objekt i jSon format. Det skal indeholde
        /// data til funktionen med følgende felter specificeret : User_Education_Time_CollectionID,
        /// CourseID.
        /// Optionalt kan følgende felter også angives : WhichCharacterScaleID, CharacterValueCourse og
        /// AbsencePercentageCourse
        /// </param>
        /// <param name="id">Integer der specificerer id på Bruger-F*g/Kursus samling.</param>
        /// <param name="Password">Password for nuværende bruger.</param>
        /// <param name="UserName">Brugernavn for nuværende bruger.</param>
        /// <returns>
        /// UpdateOperationOk (værdien 1) hvis F*g/Kursus forløb er gemt ok.
        /// Eller en retur kode med en værdi mindre end 0, hvis noget gik galt.
        /// Se en oversigt over return koder i ReturnCodesAndStrings eller klik
        /// her : <see cref="ReturnCodeAndReturnString"/>
        /// </returns>
        // PUT api/<controller>/5
        public int Put(int id, dynamic json_Object, string UserName, string Password)
        {
            User_Education_Character_Course_Collection User_Education_Character_Course_Collection_Object =
                new User_Education_Character_Course_Collection();
            WhichCharacterScale WhichCharacterScale_Object = new WhichCharacterScale();
            int NumberOfCourseCharactersSaved;

            int UserID = 0;

            UserID = UserInfo.FindUserInDatabase(UserName, Password);

            if (Const.UserNotFound < UserID)
            {
                if ((null == json_Object.User_Education_Time_CollectionID) ||
                    (null == json_Object.CourseID))
                {
                    return(Const.WrongjSonObjectParameters);
                }
                else
                {
                    User_Education_Character_Course_Collection_Object = db.User_Education_Character_Course_Collections.Find(id);

                    if (null != User_Education_Character_Course_Collection_Object)
                    {
                        if (User_Education_Character_Course_Collection_Object.User_Education_Time_Collection.UserInfoID != UserID)
                        {
                            return(Const.ObjectNotSavedByCurrentUserOriginally);
                        }

                        User_Education_Character_Course_Collection_Object.User_Education_Time_CollectionID =
                            json_Object.User_Education_Time_CollectionID;
                        User_Education_Character_Course_Collection_Object.CourseID =
                            json_Object.CourseID;

                        if (null != json_Object.WhichCharacterScaleID)
                        {
                            WhichCharacterScale_Object = db.WhichCharacterScales.Find((int)json_Object.WhichCharacterScaleID);
                            if (null == WhichCharacterScale_Object)
                            {
                                return(Const.WrongCharacterScaleProvided);
                            }
                            User_Education_Character_Course_Collection_Object.WhichCharacterScaleID = json_Object.WhichCharacterScaleID;
                        }
                        else
                        {
                            User_Education_Character_Course_Collection_Object.WhichCharacterScaleID = null;
                        }

                        if (null != json_Object.CharacterValueCourse)
                        {
                            if (null == json_Object.WhichCharacterScaleID)
                            {
                                return(Const.CharacterProvidedButNoCharacterScaleProvided);
                            }
                            else
                            {
                                int WhichCharacterScale  = WhichCharacterScale_Object.WhichCharacterScaleID;
                                int CharacterValueCourse = json_Object.CharacterValueCourse;

                                switch (WhichCharacterScale)
                                {
                                case (int)WhichCharacterScaleENUM.Character_7_ENUM:
                                    Character7Scale Character7Scale_Object = db.Character7Scales.FirstOrDefault(c => c.Character7ScaleValue == CharacterValueCourse);
                                    if (null == Character7Scale_Object)
                                    {
                                        return(Const.WrongCharacterProvided);
                                    }
                                    break;

                                case (int)WhichCharacterScaleENUM.Character_13_ENUM:
                                    Character13Scale Character13Scale_Object = db.Character13Scales.FirstOrDefault(c => c.Character13ScaleValue == CharacterValueCourse);
                                    if (null == Character13Scale_Object)
                                    {
                                        return(Const.WrongCharacterProvided);
                                    }
                                    break;
                                }
                            }
                            User_Education_Character_Course_Collection_Object.CharacterValueCourse = json_Object.CharacterValueCourse;
                        }
                        else
                        {
                            if (null != json_Object.WhichCharacterScaleID)
                            {
                                return(Const.NoCharacterProvidedButCharacterScaleProvided);
                            }
                            User_Education_Character_Course_Collection_Object.CharacterValueCourse = null;
                        }

                        if (null != json_Object.AbsencePercentageCourse)
                        {
                            User_Education_Character_Course_Collection_Object.AbsencePercentageCourse = json_Object.AbsencePercentageCourse;
                        }
                        else
                        {
                            User_Education_Character_Course_Collection_Object.AbsencePercentageCourse = null;
                        }

                        NumberOfCourseCharactersSaved = db.SaveChanges();
                        if (1 == NumberOfCourseCharactersSaved)
                        {
                            LogData.LogDataToDatabase(UserName, DataBaseOperation.UpdateData_Enum, ModelDatabaseNumber.User_Education_Character_Course_Collection_Enum);
                            return(Const.UpdateOperationOk);
                        }
                        else
                        {
                            return(Const.UpdateOperationFailed);
                        }
                    }
                    else
                    {
                        return(Const.ObjectNotFound);
                    }
                }
            }
            else
            {
                return(Const.UserNotFound);
            }
        }
        /// <summary>
        /// Opdaterer Uddannelsesforløb hørende til bruger specificeret ved id, UserName og Password.
        /// </summary>
        /// <remarks>
        /// UserName og Password skal være gemt i Web API'ets database for at være gyldige. Og
        /// Uddannelsesforløb med specificeret id, skal være gemt af nuværende bruger før.
        /// </remarks>
        /// <param name="json_Object">json_Objekt er et objekt i jSon format. Det skal indeholde
        /// data til funktionen med følgende felter specificeret : StartDate, EndDate, EducationLineID.
        /// Optionalt kan følgende felter også angives : WhichCharacterScaleID, CharacterValueEducation og
        /// AbsencePercentageEducation
        /// </param>
        /// <param name="id">Integer der specificerer id på Bruger-Uddannnelsesforløb samling.</param>
        /// <param name="Password">Password for nuværende bruger.</param>
        /// <param name="UserName">Brugernavn for nuværende bruger.</param>
        /// <returns>
        /// UpdateOperationOk (værdien 1) hvis Uddannelsesforløb er gemt ok.
        /// Eller en retur kode med en værdi mindre end 0, hvis noget gik galt.
        /// Se en oversigt over return koder i ReturnCodesAndStrings eller klik
        /// her : <see cref="ReturnCodeAndReturnString"/>
        /// </returns>
        // PUT api/<controller>/5
        public int Put(int id, dynamic json_Object, string UserName, string Password)
        {
            User_Education_Time_Collection User_Education_Time_Collection_Object =
                new User_Education_Time_Collection();
            WhichCharacterScale WhichCharacterScale_Object = new WhichCharacterScale();
            int NumberOfUserEducationsSaved;

            int UserID = 0;

            UserID = UserInfo.FindUserInDatabase(UserName, Password);

            if (Const.UserNotFound < UserID)
            {
                if ((null == json_Object.StartDate) ||
                    (null == json_Object.EndDate) ||
                    (null == json_Object.EducationLineID))
                {
                    return(Const.WrongjSonObjectParameters);
                }
                else
                {
                    User_Education_Time_Collection_Object = db.User_Education_Time_Collections.Find(id);

                    if (null != User_Education_Time_Collection_Object)
                    {
                        User_Education_Time_Collection_Object.StartDate       = json_Object.StartDate;
                        User_Education_Time_Collection_Object.EndDate         = json_Object.EndDate;
                        User_Education_Time_Collection_Object.EducationLineID = json_Object.EducationLineID;

                        List <User_Education_Time_Collection> User_Education_Time_Present_Collection_List = db.User_Education_Time_Collections.Where(u => u.UserInfoID == UserID && u.EducationLineID == User_Education_Time_Collection_Object.EducationLineID).ToList();

                        int ListCounter = 0;

                        for (ListCounter = 0; ListCounter < User_Education_Time_Present_Collection_List.Count; ListCounter++)
                        {
                            if (id != User_Education_Time_Present_Collection_List[ListCounter].User_Education_Time_CollectionID)
                            {
                                if ((User_Education_Time_Collection_Object.StartDate ==
                                     User_Education_Time_Present_Collection_List[ListCounter].StartDate) &&
                                    (User_Education_Time_Collection_Object.EndDate ==
                                     User_Education_Time_Present_Collection_List[ListCounter].EndDate))
                                {
                                    return(Const.UserAlreadySignedUpForEducation);
                                }
                            }
                        }

                        if (null != json_Object.WhichCharacterScaleID)
                        {
                            WhichCharacterScale_Object = db.WhichCharacterScales.Find((int)json_Object.WhichCharacterScaleID);
                            if (null == WhichCharacterScale_Object)
                            {
                                return(Const.WrongCharacterScaleProvided);
                            }
                            User_Education_Time_Collection_Object.WhichCharacterScaleID = json_Object.WhichCharacterScaleID;
                        }
                        else
                        {
                            User_Education_Time_Collection_Object.WhichCharacterScaleID = null;
                        }

                        if (null != json_Object.CharacterValueEducation)
                        {
                            if (null == json_Object.WhichCharacterScaleID)
                            {
                                return(Const.CharacterProvidedButNoCharacterScaleProvided);
                            }
                            else
                            {
                                int WhichCharacterScale     = WhichCharacterScale_Object.WhichCharacterScaleID;
                                int CharacterValueEducation = json_Object.CharacterValueEducation;

                                switch (WhichCharacterScale)
                                {
                                case (int)WhichCharacterScaleENUM.Character_7_ENUM:
                                    Character7Scale Character7Scale_Object = db.Character7Scales.FirstOrDefault(c => c.Character7ScaleValue == CharacterValueEducation);
                                    if (null == Character7Scale_Object)
                                    {
                                        return(Const.WrongCharacterProvided);
                                    }
                                    break;

                                case (int)WhichCharacterScaleENUM.Character_13_ENUM:
                                    Character13Scale Character13Scale_Object = db.Character13Scales.FirstOrDefault(c => c.Character13ScaleValue == CharacterValueEducation);
                                    if (null == Character13Scale_Object)
                                    {
                                        return(Const.WrongCharacterProvided);
                                    }
                                    break;
                                }
                            }
                            User_Education_Time_Collection_Object.CharacterValueEducation = json_Object.CharacterValueEducation;
                        }
                        else
                        {
                            if (null != json_Object.WhichCharacterScaleID)
                            {
                                return(Const.NoCharacterProvidedButCharacterScaleProvided);
                            }
                            User_Education_Time_Collection_Object.CharacterValueEducation = null;
                        }

                        if (null != json_Object.AbsencePercentageEducation)
                        {
                            User_Education_Time_Collection_Object.AbsencePercentageEducation = json_Object.AbsencePercentageEducation;
                        }
                        else
                        {
                            User_Education_Time_Collection_Object.AbsencePercentageEducation = null;
                        }

                        NumberOfUserEducationsSaved = db.SaveChanges();
                        if (1 == NumberOfUserEducationsSaved)
                        {
                            LogData.LogDataToDatabase(UserName, DataBaseOperation.UpdateData_Enum, ModelDatabaseNumber.User_Eductaion_Time_Collection_Enum);
                            return(Const.UpdateOperationOk);
                        }
                        else
                        {
                            return(Const.UpdateOperationFailed);
                        }
                    }
                    else
                    {
                        return(Const.ObjectNotFound);
                    }
                }
            }
            else
            {
                return(Const.UserNotFound);
            }
        }