// Check
        public string TVTypeUserAuthorizationModelOK(TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel)
        {
            string retStr = FieldCheckNotZeroInt(tvTypeUserAuthorizationModel.ContactTVItemID, ServiceRes.ContactTVItemID);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.TVTypeOK(tvTypeUserAuthorizationModel.TVType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.TVAuthOK(tvTypeUserAuthorizationModel.TVAuth);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.DBCommandOK(tvTypeUserAuthorizationModel.DBCommand);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            return("");
        }
        public TVTypeUserAuthorizationModel GetTVTypeUserAuthorizationModelWithTVTypeUserAuthorizationIDDB(int TVTypeUserAuthorizationID)
        {
            TVItemService tvItemService = new TVItemService(this.LanguageRequest, this.User);

            TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel = (from c in db.TVTypeUserAuthorizations
                                                                         where c.TVTypeUserAuthorizationID == TVTypeUserAuthorizationID
                                                                         select new TVTypeUserAuthorizationModel
            {
                Error = "",
                TVTypeUserAuthorizationID = c.TVTypeUserAuthorizationID,
                DBCommand = (DBCommandEnum)c.DBCommand,
                ContactTVItemID = c.ContactTVItemID,
                TVType = (TVTypeEnum)c.TVType,
                TVPath = "",
                TVLevel = -1,
                TVAuth = (TVAuthEnum)c.TVAuth,
                LastUpdateDate_UTC = c.LastUpdateDate_UTC,
                LastUpdateContactTVItemID = c.LastUpdateContactTVItemID,
            }).FirstOrDefault <TVTypeUserAuthorizationModel>();

            if (tvTypeUserAuthorizationModel == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, BaseEnumServiceRes.TVTypeUserAuthorization, BaseEnumServiceRes.TVTypeUserAuthorizationID, TVTypeUserAuthorizationID)));
            }

            tvTypeUserAuthorizationModel.TVPath  = tvTypeNamesAndPathList.Where(c => c.Index == (int)tvTypeUserAuthorizationModel.TVType).FirstOrDefault().TVPath;
            tvTypeUserAuthorizationModel.TVLevel = tvItemService.GetTVLevel(tvTypeUserAuthorizationModel.TVPath);

            return(tvTypeUserAuthorizationModel);
        }
Esempio n. 3
0
        public void AdminController_RemoveUserTVTypeAuthJSON_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);

                // Arrange
                controllerAction = "RemoveUserTVTypeAuthJSON";


                // Act
                SetupTest(contactModelListGood[0], culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    TVTypeUserAuthorizationService tvTypeUserAuthorizationService = new TVTypeUserAuthorizationService(languageEnum, user);

                    // Arrange
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelNew = new TVTypeUserAuthorizationModel();
                    tvTypeUserAuthorizationModelNew.ContactTVItemID = contactModelListGood[2].ContactTVItemID;
                    tvTypeUserAuthorizationModelNew.TVType          = TVTypeEnum.Country;
                    tvTypeUserAuthorizationModelNew.TVAuth          = TVAuthEnum.Delete;

                    // Act
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelRet = tvTypeUserAuthorizationService.PostAddTVTypeUserAuthorizationDB(tvTypeUserAuthorizationModelNew);

                    // Assert
                    Assert.IsNotNull(tvTypeUserAuthorizationModelRet);
                    Assert.AreEqual(contactModelListGood[2].ContactTVItemID, tvTypeUserAuthorizationModelRet.ContactTVItemID);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.ContactTVItemID, tvTypeUserAuthorizationModelRet.ContactTVItemID);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.TVType, tvTypeUserAuthorizationModelRet.TVType);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.TVAuth, tvTypeUserAuthorizationModelRet.TVAuth);


                    // Act
                    JsonResult jsonResult = controller.RemoveUserTVTypeAuthJSON(tvTypeUserAuthorizationModelRet.ContactTVItemID, tvTypeUserAuthorizationModelRet.TVType) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    string retStr = (string)jsonResult.Data;
                    Assert.AreEqual("", retStr);

                    // Act
                    SetupTest(contactModelListGood[1], culture, controllerAction);

                    // Act
                    jsonResult = controller.RemoveUserTVTypeAuthJSON(tvTypeUserAuthorizationModelRet.ContactTVItemID, tvTypeUserAuthorizationModelRet.TVType) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    retStr = (string)jsonResult.Data;
                    Assert.AreEqual(ControllerRes.NeedToBeAnAdministrator, retStr);
                }
            }
        }
Esempio n. 4
0
        public JsonResult RemoveUserTVTypeAuthJSON(int ContactTVItemID, TVTypeEnum TVType)
        {
            if (!CheckIsAdmin())
            {
                return(Json(ControllerRes.NeedToBeAnAdministrator, JsonRequestBehavior.AllowGet));
            }

            TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelRet = _TVTypeUserAuthorizationService.PostDeleteTVTypeUserAuthorizationWithContactTVItemIDAndTVTypeDB(ContactTVItemID, TVType);

            return(Json(tvTypeUserAuthorizationModelRet.Error, JsonRequestBehavior.AllowGet));
        }
        public TVTypeUserAuthorizationModel PostDeleteTVTypeUserAuthorizationWithContactTVItemIDAndTVTypeDB(int ContactTVItemID, TVTypeEnum TVType)
        {
            TVTypeUserAuthorizationModel TVTypeUserAuthorizationModel = GetTVTypeUserAuthorizationModelWithContactTVItemIDAndTVTypeDB(ContactTVItemID, TVType);

            if (!string.IsNullOrWhiteSpace(TVTypeUserAuthorizationModel.Error))
            {
                return(ReturnError(TVTypeUserAuthorizationModel.Error));
            }

            return(PostDeleteTVTypeUserAuthorizationDB(TVTypeUserAuthorizationModel.TVTypeUserAuthorizationID));
        }
Esempio n. 6
0
        public void AdminController_GetUserTVTypeAuthJSON_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);

                // Arrange
                controllerAction = "GetUserTVTypeAuthJSON";

                // Act
                SetupTest(contactModelListGood[0], culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    TVTypeUserAuthorizationService tvTypeUserAuthorizationService = new TVTypeUserAuthorizationService(languageEnum, user);

                    // Arrange
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelNew = new TVTypeUserAuthorizationModel();
                    tvTypeUserAuthorizationModelNew.ContactTVItemID = contactModelListGood[2].ContactTVItemID;
                    tvTypeUserAuthorizationModelNew.TVType          = TVTypeEnum.Country;
                    tvTypeUserAuthorizationModelNew.TVAuth          = TVAuthEnum.Delete;

                    // Act
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelRet = tvTypeUserAuthorizationService.PostAddTVTypeUserAuthorizationDB(tvTypeUserAuthorizationModelNew);

                    // Assert
                    Assert.IsNotNull(tvTypeUserAuthorizationModelRet);
                    Assert.AreEqual(contactModelListGood[2].ContactTVItemID, tvTypeUserAuthorizationModelRet.ContactTVItemID);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.ContactTVItemID, tvTypeUserAuthorizationModelRet.ContactTVItemID);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.TVType, tvTypeUserAuthorizationModelRet.TVType);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.TVAuth, tvTypeUserAuthorizationModelRet.TVAuth);

                    // Act
                    JsonResult jsonResult = controller.GetUserTVTypeAuthJSON(contactModelListGood[2].ContactTVItemID) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    List <TVTypeUserAuthorizationModel> tvTypeUserAuthorizationModelList = (List <TVTypeUserAuthorizationModel>)jsonResult.Data;
                    Assert.IsTrue(tvTypeUserAuthorizationModelList.Where(c => c.ContactTVItemID == contactModelListGood[2].ContactTVItemID).Any());

                    // Act
                    SetupTest(contactModelListGood[1], culture, controllerAction);

                    // Act
                    jsonResult = controller.GetUserTVTypeAuthJSON(contactModelListGood[2].ContactTVItemID) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    tvTypeUserAuthorizationModelList = (List <TVTypeUserAuthorizationModel>)jsonResult.Data;
                    Assert.AreEqual(0, tvTypeUserAuthorizationModelList.Count);
                }
            }
        }
Esempio n. 7
0
        public JsonResult SetUserTVTypeAuthJSON(TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel)
        {
            if (!CheckIsAdmin())
            {
                return(Json(new TVTypeUserAuthorizationModel()
                {
                    Error = ControllerRes.NeedToBeAnAdministrator
                }, JsonRequestBehavior.AllowGet));
            }

            TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelRet = _TVTypeUserAuthorizationService.PostSetTVTypeUserAuthorizationDB(tvTypeUserAuthorizationModel);

            return(Json(tvTypeUserAuthorizationModelRet, JsonRequestBehavior.AllowGet));
        }
        public TVTypeUserAuthorizationModel PostSetTVTypeUserAuthorizationDB(TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel)
        {
            TVTypeUserAuthorization tvTypeUserAuthorizationToUpdate = GetTVTypeUserAuthorizationWithContactTVItemIDAndTVTypeDB(tvTypeUserAuthorizationModel.ContactTVItemID, tvTypeUserAuthorizationModel.TVType);

            if (tvTypeUserAuthorizationToUpdate == null)
            {
                tvTypeUserAuthorizationModel.DBCommand = DBCommandEnum.Original;

                return(PostAddTVTypeUserAuthorizationDB(tvTypeUserAuthorizationModel));
            }
            else
            {
                return(PostUpdateTVTypeUserAuthorizationDB(tvTypeUserAuthorizationModel));
            }
        }
        public TVTypeUserAuthorizationModel PostUpdateTVTypeUserAuthorizationDB(TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel)
        {
            string retStr = TVTypeUserAuthorizationModelOK(tvTypeUserAuthorizationModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            bool IsAdmin = IsAdministratorDB(User.Identity.Name);

            if (!IsAdmin)
            {
                return(ReturnError(ServiceRes.OnlyAdministratorsCanManageUsers));
            }

            ContactModel contactModel = GetContactModelWithContactTVItemIDDB(tvTypeUserAuthorizationModel.ContactTVItemID);

            if (!string.IsNullOrWhiteSpace(contactModel.Error))
            {
                return(ReturnError(contactModel.Error));
            }

            ContactModel contactModelLoggedIn = GetContactLoggedInDB();

            if (!string.IsNullOrWhiteSpace(contactModelLoggedIn.Error))
            {
                return(ReturnError(contactModelLoggedIn.Error));
            }

            if (contactOK.ContactTVItemID == tvTypeUserAuthorizationModel.ContactTVItemID)
            {
                return(ReturnError(ServiceRes.CantSetOwnAuthorization));
            }

            TVTypeUserAuthorization tvTypeUserAuthorizationToUpdate = new TVTypeUserAuthorization();

            if (tvTypeUserAuthorizationModel.TVTypeUserAuthorizationID != 0)
            {
                tvTypeUserAuthorizationToUpdate = GetTVTypeUserAuthorizationWithTVTypeUserAuthorizationIDDB(tvTypeUserAuthorizationModel.TVTypeUserAuthorizationID);
                if (tvTypeUserAuthorizationToUpdate == null)
                {
                    return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, BaseEnumServiceRes.TVTypeUserAuthorization)));
                }
            }
            else
            {
                tvTypeUserAuthorizationToUpdate = GetTVTypeUserAuthorizationWithContactTVItemIDAndTVTypeDB(tvTypeUserAuthorizationModel.ContactTVItemID, tvTypeUserAuthorizationModel.TVType);
                if (tvTypeUserAuthorizationToUpdate == null)
                {
                    return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, BaseEnumServiceRes.TVTypeUserAuthorization)));
                }
            }

            retStr = FillTVTypeUserAuthorization(tvTypeUserAuthorizationToUpdate, tvTypeUserAuthorizationModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("TVTypeUserAuthorizations", tvTypeUserAuthorizationToUpdate.TVTypeUserAuthorizationID, LogCommandEnum.Change, tvTypeUserAuthorizationToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }

            if (tvTypeUserAuthorizationModel.TVType == TVTypeEnum.Root)
            {
                if (tvTypeUserAuthorizationModel.TVAuth == TVAuthEnum.Admin)
                {
                    contactModel.IsAdmin = true;
                }
                else
                {
                    contactModel.IsAdmin = false;
                }

                ContactService contactService  = new ContactService(LanguageRequest, User);
                ContactModel   contactModelRet = contactService.PostUpdateContactDB(contactModel);
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }
            }

            return(GetTVTypeUserAuthorizationModelWithTVTypeUserAuthorizationIDDB(tvTypeUserAuthorizationToUpdate.TVTypeUserAuthorizationID));
        }
        // Post
        public TVTypeUserAuthorizationModel PostAddTVTypeUserAuthorizationDB(TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel)
        {
            string retStr = TVTypeUserAuthorizationModelOK(tvTypeUserAuthorizationModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            bool IsAdmin = IsAdministratorDB(User.Identity.Name);

            if (!IsAdmin)
            {
                return(ReturnError(ServiceRes.OnlyAdministratorsCanManageUsers));
            }

            ContactModel contactModel = GetContactModelWithContactTVItemIDDB(tvTypeUserAuthorizationModel.ContactTVItemID);

            if (!string.IsNullOrWhiteSpace(contactModel.Error))
            {
                return(ReturnError(contactModel.Error));
            }

            ContactModel contactModelLoggedIn = GetContactLoggedInDB();

            if (!string.IsNullOrWhiteSpace(contactModelLoggedIn.Error))
            {
                return(ReturnError(contactModelLoggedIn.Error));
            }

            if (contactOK.ContactTVItemID == tvTypeUserAuthorizationModel.ContactTVItemID)
            {
                return(ReturnError(ServiceRes.CantSetOwnAuthorization));
            }

            TVTypeUserAuthorization tvTypeUserAuthorizationExist = GetTVTypeUserAuthorizationWithContactTVItemIDAndTVTypeDB(tvTypeUserAuthorizationModel.ContactTVItemID, tvTypeUserAuthorizationModel.TVType);

            if (tvTypeUserAuthorizationExist != null)
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, BaseEnumServiceRes.TVTypeUserAuthorization)));
            }

            TVTypeUserAuthorization tvTypeUserAuthorizationNew = new TVTypeUserAuthorization();

            retStr = FillTVTypeUserAuthorization(tvTypeUserAuthorizationNew, tvTypeUserAuthorizationModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.TVTypeUserAuthorizations.Add(tvTypeUserAuthorizationNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("TVTypeUserAuthorizations", tvTypeUserAuthorizationNew.TVTypeUserAuthorizationID, LogCommandEnum.Add, tvTypeUserAuthorizationNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetTVTypeUserAuthorizationModelWithTVTypeUserAuthorizationIDDB(tvTypeUserAuthorizationNew.TVTypeUserAuthorizationID));
        }
        // Fill
        public string FillTVTypeUserAuthorization(TVTypeUserAuthorization tvTypeUserAuthorization, TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel, ContactOK contactOK)
        {
            tvTypeUserAuthorization.DBCommand          = (int)tvTypeUserAuthorizationModel.DBCommand;
            tvTypeUserAuthorization.ContactTVItemID    = tvTypeUserAuthorizationModel.ContactTVItemID;
            tvTypeUserAuthorization.TVType             = (int)tvTypeUserAuthorizationModel.TVType;
            tvTypeUserAuthorization.TVAuth             = (int)tvTypeUserAuthorizationModel.TVAuth;
            tvTypeUserAuthorization.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                tvTypeUserAuthorization.LastUpdateContactTVItemID = 2;
            }
            else
            {
                tvTypeUserAuthorization.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
Esempio n. 12
0
        public void AdminController_SetUserTVTypeAuthJSON_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                LanguageEnum languageEnum = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);

                // Arrange
                controllerAction = "SetUserTVTypeAuthJSON";

                // Act
                SetupTest(contactModelListGood[0], culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    TVTypeUserAuthorizationService tvTypeUserAuthorizationService = new TVTypeUserAuthorizationService(languageEnum, user);

                    // Arrange
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelNew = new TVTypeUserAuthorizationModel();
                    tvTypeUserAuthorizationModelNew.ContactTVItemID = contactModelListGood[2].ContactTVItemID;
                    tvTypeUserAuthorizationModelNew.TVType          = TVTypeEnum.Country;
                    tvTypeUserAuthorizationModelNew.TVAuth          = TVAuthEnum.Delete;

                    // Act
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModelRet = tvTypeUserAuthorizationService.GetTVTypeUserAuthorizationModelWithContactTVItemIDAndTVTypeDB(tvTypeUserAuthorizationModelNew.ContactTVItemID, tvTypeUserAuthorizationModelNew.TVType);

                    if (tvTypeUserAuthorizationModelRet.TVTypeUserAuthorizationID > 0)
                    {
                        // Act
                        tvTypeUserAuthorizationModelRet = tvTypeUserAuthorizationService.PostDeleteTVTypeUserAuthorizationDB(tvTypeUserAuthorizationModelRet.TVTypeUserAuthorizationID);

                        // Assert
                        Assert.AreEqual("", tvTypeUserAuthorizationModelRet.Error);
                    }

                    // Act
                    JsonResult jsonResult = controller.SetUserTVTypeAuthJSON(tvTypeUserAuthorizationModelNew) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel = (TVTypeUserAuthorizationModel)jsonResult.Data;
                    Assert.AreEqual("", tvTypeUserAuthorizationModel.Error);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.ContactTVItemID, tvTypeUserAuthorizationModel.ContactTVItemID);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.TVType, tvTypeUserAuthorizationModel.TVType);
                    Assert.AreEqual(tvTypeUserAuthorizationModelNew.TVAuth, tvTypeUserAuthorizationModel.TVAuth);


                    tvTypeUserAuthorizationModel.TVAuth = TVAuthEnum.Create;

                    // Act
                    jsonResult = controller.SetUserTVTypeAuthJSON(tvTypeUserAuthorizationModel) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    TVTypeUserAuthorizationModel tvTypeUserAuthorizationModel2 = (TVTypeUserAuthorizationModel)jsonResult.Data;
                    Assert.AreEqual("", tvTypeUserAuthorizationModel2.Error);
                    Assert.AreEqual(tvTypeUserAuthorizationModel.ContactTVItemID, tvTypeUserAuthorizationModel2.ContactTVItemID);
                    Assert.AreEqual(tvTypeUserAuthorizationModel.TVType, tvTypeUserAuthorizationModel2.TVType);
                    Assert.AreEqual(tvTypeUserAuthorizationModel.TVAuth, tvTypeUserAuthorizationModel2.TVAuth);

                    // Act
                    SetupTest(contactModelListGood[1], culture, controllerAction);

                    // Act
                    jsonResult = controller.SetUserTVTypeAuthJSON(tvTypeUserAuthorizationModel) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    tvTypeUserAuthorizationModel2 = (TVTypeUserAuthorizationModel)jsonResult.Data;
                    Assert.AreEqual(ControllerRes.NeedToBeAnAdministrator, tvTypeUserAuthorizationModel2.Error);
                }
            }
        }