public TVItemUserAuthorizationModel PostUpdateTVItemUserAuthorizationDB(TVItemUserAuthorizationModel tvItemUserAuthorizationModel) { string retStr = TVItemUserAuthorizationModelOK(tvItemUserAuthorizationModel); 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)); } TVItemUserAuthorization tvItemUserAuthorizationToUpdate = GetTVItemUserAuthorizationWithTVItemUserAuthorizationIDDB(tvItemUserAuthorizationModel.TVItemUserAuthorizationID); if (tvItemUserAuthorizationToUpdate == null) { return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.TVItemUserAuthorization))); } if (contactOK.ContactTVItemID == tvItemUserAuthorizationToUpdate.ContactTVItemID) { return(ReturnError(ServiceRes.CantSetOwnAuthorization)); } retStr = FillTVItemUserAuthorization(tvItemUserAuthorizationToUpdate, tvItemUserAuthorizationModel, 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("TVItemUserAuthorizations", tvItemUserAuthorizationToUpdate.TVItemUserAuthorizationID, LogCommandEnum.Change, tvItemUserAuthorizationToUpdate); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetTVItemUserAuthorizationModelWithTVItemUserAuthorizationIDDB(tvItemUserAuthorizationToUpdate.TVItemUserAuthorizationID)); }
public TVItemUserAuthorization GetTVItemUserAuthorizationWithTVItemUserAuthorizationIDDB(int TVItemUserAuthorizationID) { TVItemUserAuthorization TVItemUserAuthorization = (from c in db.TVItemUserAuthorizations where c.TVItemUserAuthorizationID == TVItemUserAuthorizationID select c).FirstOrDefault <TVItemUserAuthorization>(); return(TVItemUserAuthorization); }
public void TVItemUserAuthorization_Controller_Put_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemUserAuthorizationController tvItemUserAuthorizationController = new TVItemUserAuthorizationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemUserAuthorizationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemUserAuthorizationController.DatabaseType); TVItemUserAuthorization tvItemUserAuthorizationLast = new TVItemUserAuthorization(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(query, db, ContactID); tvItemUserAuthorizationLast = (from c in db.TVItemUserAuthorizations select c).FirstOrDefault(); } // ok with TVItemUserAuthorization info IHttpActionResult jsonRet = tvItemUserAuthorizationController.GetTVItemUserAuthorizationWithID(tvItemUserAuthorizationLast.TVItemUserAuthorizationID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemUserAuthorization> Ret = jsonRet as OkNegotiatedContentResult <TVItemUserAuthorization>; TVItemUserAuthorization tvItemUserAuthorizationRet = Ret.Content; Assert.AreEqual(tvItemUserAuthorizationLast.TVItemUserAuthorizationID, tvItemUserAuthorizationRet.TVItemUserAuthorizationID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Put to return success IHttpActionResult jsonRet2 = tvItemUserAuthorizationController.Put(tvItemUserAuthorizationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemUserAuthorization> tvItemUserAuthorizationRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemUserAuthorization>; Assert.IsNotNull(tvItemUserAuthorizationRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNull(badRequest2); // Put to return CSSPError because TVItemUserAuthorizationID of 0 does not exist tvItemUserAuthorizationRet.TVItemUserAuthorizationID = 0; IHttpActionResult jsonRet3 = tvItemUserAuthorizationController.Put(tvItemUserAuthorizationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); OkNegotiatedContentResult <TVItemUserAuthorization> tvItemUserAuthorizationRet3 = jsonRet3 as OkNegotiatedContentResult <TVItemUserAuthorization>; Assert.IsNull(tvItemUserAuthorizationRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest3); } } }
public TVItemUserAuthorization GetTVItemUserAuthorizationWithContactTVItemIDTVItemID1TVItemID2TVItemID3TVItemID4DB(int ContactTVItemID, int TVItemID1, int?TVItemID2, int?TVItemID3, int?TVItemID4) { TVItemUserAuthorization TVItemUserAuthorization = (from c in db.TVItemUserAuthorizations where c.ContactTVItemID == ContactTVItemID && c.TVItemID1 == TVItemID1 && c.TVItemID2 == TVItemID2 && c.TVItemID3 == TVItemID3 && c.TVItemID4 == TVItemID4 select c).FirstOrDefault <TVItemUserAuthorization>(); return(TVItemUserAuthorization); }
public IHttpActionResult GetTVItemUserAuthorizationWithID([FromUri] int TVItemUserAuthorizationID, [FromUri] string lang = "en", [FromUri] string extra = "") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); tvItemUserAuthorizationService.Query = tvItemUserAuthorizationService.FillQuery(typeof(TVItemUserAuthorization), lang, 0, 1, "", "", extra); if (tvItemUserAuthorizationService.Query.Extra == "A") { TVItemUserAuthorizationExtraA tvItemUserAuthorizationExtraA = new TVItemUserAuthorizationExtraA(); tvItemUserAuthorizationExtraA = tvItemUserAuthorizationService.GetTVItemUserAuthorizationExtraAWithTVItemUserAuthorizationID(TVItemUserAuthorizationID); if (tvItemUserAuthorizationExtraA == null) { return(NotFound()); } return(Ok(tvItemUserAuthorizationExtraA)); } else if (tvItemUserAuthorizationService.Query.Extra == "B") { TVItemUserAuthorizationExtraB tvItemUserAuthorizationExtraB = new TVItemUserAuthorizationExtraB(); tvItemUserAuthorizationExtraB = tvItemUserAuthorizationService.GetTVItemUserAuthorizationExtraBWithTVItemUserAuthorizationID(TVItemUserAuthorizationID); if (tvItemUserAuthorizationExtraB == null) { return(NotFound()); } return(Ok(tvItemUserAuthorizationExtraB)); } else { TVItemUserAuthorization tvItemUserAuthorization = new TVItemUserAuthorization(); tvItemUserAuthorization = tvItemUserAuthorizationService.GetTVItemUserAuthorizationWithTVItemUserAuthorizationID(TVItemUserAuthorizationID); if (tvItemUserAuthorization == null) { return(NotFound()); } return(Ok(tvItemUserAuthorization)); } } }
public TVItemUserAuthorizationModel PostSetTVItemUserAuthorizationDB(TVItemUserAuthorizationModel tvItemUserAuthorizationModel) { TVItemUserAuthorization tvItemUserAuthorizationToUpdate = GetTVItemUserAuthorizationWithContactTVItemIDTVItemID1TVItemID2TVItemID3TVItemID4DB(tvItemUserAuthorizationModel.ContactTVItemID, tvItemUserAuthorizationModel.TVItemID1, null, null, null); if (tvItemUserAuthorizationToUpdate == null) { tvItemUserAuthorizationModel.DBCommand = DBCommandEnum.Original; return(PostAddTVItemUserAuthorizationDB(tvItemUserAuthorizationModel)); } else { return(PostUpdateTVItemUserAuthorizationDB(tvItemUserAuthorizationModel)); } }
/// <summary> /// Tries to execute the CSSPDB transaction (add/delete/update) on an [TVItemUserAuthorization](CSSPModels.TVItemUserAuthorization.html) item /// </summary> /// <param name="tvItemUserAuthorization">Is the TVItemUserAuthorization item the client want to add to CSSPDB. What's important here is the TVItemUserAuthorizationID</param> /// <returns>true if TVItemUserAuthorization item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns> private bool TryToSave(TVItemUserAuthorization tvItemUserAuthorization) { try { db.SaveChanges(); } catch (DbUpdateException ex) { tvItemUserAuthorization.ValidationResults = new List <ValidationResult>() { new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : "")) }.AsEnumerable(); return(false); } return(true); }
/// <summary> /// Updates an [TVItemUserAuthorization](CSSPModels.TVItemUserAuthorization.html) item in CSSPDB /// </summary> /// <param name="tvItemUserAuthorization">Is the TVItemUserAuthorization item the client want to add to CSSPDB. What's important here is the TVItemUserAuthorizationID</param> /// <returns>true if TVItemUserAuthorization item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns> public bool Update(TVItemUserAuthorization tvItemUserAuthorization) { tvItemUserAuthorization.ValidationResults = Validate(new ValidationContext(tvItemUserAuthorization), ActionDBTypeEnum.Update); if (tvItemUserAuthorization.ValidationResults.Count() > 0) { return(false); } db.TVItemUserAuthorizations.Update(tvItemUserAuthorization); if (!TryToSave(tvItemUserAuthorization)) { return(false); } return(true); }
public void TVItemUserAuthorization_Controller_GetTVItemUserAuthorizationWithID_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemUserAuthorizationController tvItemUserAuthorizationController = new TVItemUserAuthorizationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemUserAuthorizationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemUserAuthorizationController.DatabaseType); TVItemUserAuthorization tvItemUserAuthorizationFirst = new TVItemUserAuthorization(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(new Query(), db, ContactID); tvItemUserAuthorizationFirst = (from c in db.TVItemUserAuthorizations select c).FirstOrDefault(); } // ok with TVItemUserAuthorization info IHttpActionResult jsonRet = tvItemUserAuthorizationController.GetTVItemUserAuthorizationWithID(tvItemUserAuthorizationFirst.TVItemUserAuthorizationID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemUserAuthorization> Ret = jsonRet as OkNegotiatedContentResult <TVItemUserAuthorization>; TVItemUserAuthorization tvItemUserAuthorizationRet = Ret.Content; Assert.AreEqual(tvItemUserAuthorizationFirst.TVItemUserAuthorizationID, tvItemUserAuthorizationRet.TVItemUserAuthorizationID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Not Found IHttpActionResult jsonRet2 = tvItemUserAuthorizationController.GetTVItemUserAuthorizationWithID(0); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemUserAuthorization> tvItemUserAuthorizationRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemUserAuthorization>; Assert.IsNull(tvItemUserAuthorizationRet2); NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult; Assert.IsNotNull(notFoundRequest); } } }
public IHttpActionResult Delete([FromBody] TVItemUserAuthorization tvItemUserAuthorization, [FromUri] string lang = "en") { using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(new Query() { Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en) }, db, ContactID); if (!tvItemUserAuthorizationService.Delete(tvItemUserAuthorization)) { return(BadRequest(String.Join("|||", tvItemUserAuthorization.ValidationResults))); } else { tvItemUserAuthorization.ValidationResults = null; return(Ok(tvItemUserAuthorization)); } } }
// Fill public string FillTVItemUserAuthorization(TVItemUserAuthorization tvItemUserAuthorization, TVItemUserAuthorizationModel tvItemUserAuthorizationModel, ContactOK contactOK) { tvItemUserAuthorization.DBCommand = (int)tvItemUserAuthorizationModel.DBCommand; tvItemUserAuthorization.ContactTVItemID = tvItemUserAuthorizationModel.ContactTVItemID; tvItemUserAuthorization.TVItemID1 = tvItemUserAuthorizationModel.TVItemID1; tvItemUserAuthorization.TVItemID2 = tvItemUserAuthorizationModel.TVItemID2; tvItemUserAuthorization.TVItemID3 = tvItemUserAuthorizationModel.TVItemID3; tvItemUserAuthorization.TVItemID4 = tvItemUserAuthorizationModel.TVItemID4; tvItemUserAuthorization.TVAuth = (int)tvItemUserAuthorizationModel.TVAuth; tvItemUserAuthorization.LastUpdateDate_UTC = DateTime.UtcNow; if (contactOK == null) { tvItemUserAuthorization.LastUpdateContactTVItemID = 2; } else { tvItemUserAuthorization.LastUpdateContactTVItemID = contactOK.ContactTVItemID; } return(""); }
public void TVItemUserAuthorization_Controller_GetTVItemUserAuthorizationList_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemUserAuthorizationController tvItemUserAuthorizationController = new TVItemUserAuthorizationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemUserAuthorizationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemUserAuthorizationController.DatabaseType); TVItemUserAuthorization tvItemUserAuthorizationFirst = new TVItemUserAuthorization(); int count = -1; Query query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(query, db, ContactID); tvItemUserAuthorizationFirst = (from c in db.TVItemUserAuthorizations select c).FirstOrDefault(); count = (from c in db.TVItemUserAuthorizations select c).Count(); count = (query.Take > count ? count : query.Take); } // ok with TVItemUserAuthorization info IHttpActionResult jsonRet = tvItemUserAuthorizationController.GetTVItemUserAuthorizationList(); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <List <TVItemUserAuthorization> > ret = jsonRet as OkNegotiatedContentResult <List <TVItemUserAuthorization> >; Assert.AreEqual(tvItemUserAuthorizationFirst.TVItemUserAuthorizationID, ret.Content[0].TVItemUserAuthorizationID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); List <TVItemUserAuthorization> tvItemUserAuthorizationList = new List <TVItemUserAuthorization>(); count = -1; query = new Query(); using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB)) { TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(query, db, ContactID); tvItemUserAuthorizationList = (from c in db.TVItemUserAuthorizations select c).OrderBy(c => c.TVItemUserAuthorizationID).Skip(0).Take(2).ToList(); count = (from c in db.TVItemUserAuthorizations select c).Count(); } if (count > 0) { query.Skip = 0; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with TVItemUserAuthorization info jsonRet = tvItemUserAuthorizationController.GetTVItemUserAuthorizationList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet); ret = jsonRet as OkNegotiatedContentResult <List <TVItemUserAuthorization> >; Assert.AreEqual(tvItemUserAuthorizationList[0].TVItemUserAuthorizationID, ret.Content[0].TVItemUserAuthorizationID); Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count); if (count > 1) { query.Skip = 1; query.Take = 5; count = (query.Take > count ? query.Take : count); // ok with TVItemUserAuthorization info IHttpActionResult jsonRet2 = tvItemUserAuthorizationController.GetTVItemUserAuthorizationList(query.Language.ToString(), query.Skip, query.Take); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <List <TVItemUserAuthorization> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <TVItemUserAuthorization> >; Assert.AreEqual(tvItemUserAuthorizationList[1].TVItemUserAuthorizationID, ret2.Content[0].TVItemUserAuthorizationID); Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count); } } } } }
public void TVItemUserAuthorization_Controller_Post_Test() { foreach (LanguageEnum LanguageRequest in AllowableLanguages) { foreach (int ContactID in new List <int>() { AdminContactID }) //, TestEmailValidatedContactID, TestEmailNotValidatedContactID }) { TVItemUserAuthorizationController tvItemUserAuthorizationController = new TVItemUserAuthorizationController(DatabaseTypeEnum.SqlServerTestDB); Assert.IsNotNull(tvItemUserAuthorizationController); Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, tvItemUserAuthorizationController.DatabaseType); TVItemUserAuthorization tvItemUserAuthorizationLast = new TVItemUserAuthorization(); using (CSSPDBContext db = new CSSPDBContext(DatabaseType)) { Query query = new Query(); query.Language = LanguageRequest; query.Asc = ""; query.Desc = ""; TVItemUserAuthorizationService tvItemUserAuthorizationService = new TVItemUserAuthorizationService(query, db, ContactID); tvItemUserAuthorizationLast = (from c in db.TVItemUserAuthorizations select c).FirstOrDefault(); } // ok with TVItemUserAuthorization info IHttpActionResult jsonRet = tvItemUserAuthorizationController.GetTVItemUserAuthorizationWithID(tvItemUserAuthorizationLast.TVItemUserAuthorizationID); Assert.IsNotNull(jsonRet); OkNegotiatedContentResult <TVItemUserAuthorization> Ret = jsonRet as OkNegotiatedContentResult <TVItemUserAuthorization>; TVItemUserAuthorization tvItemUserAuthorizationRet = Ret.Content; Assert.AreEqual(tvItemUserAuthorizationLast.TVItemUserAuthorizationID, tvItemUserAuthorizationRet.TVItemUserAuthorizationID); BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult; Assert.IsNull(badRequest); // Post to return CSSPError because TVItemUserAuthorizationID exist IHttpActionResult jsonRet2 = tvItemUserAuthorizationController.Post(tvItemUserAuthorizationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet2); OkNegotiatedContentResult <TVItemUserAuthorization> tvItemUserAuthorizationRet2 = jsonRet2 as OkNegotiatedContentResult <TVItemUserAuthorization>; Assert.IsNull(tvItemUserAuthorizationRet2); BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult; Assert.IsNotNull(badRequest2); // Post to return newly added TVItemUserAuthorization tvItemUserAuthorizationRet.TVItemUserAuthorizationID = 0; tvItemUserAuthorizationController.Request = new System.Net.Http.HttpRequestMessage(); tvItemUserAuthorizationController.Request.RequestUri = new System.Uri("http://localhost:5000/api/tvItemUserAuthorization"); IHttpActionResult jsonRet3 = tvItemUserAuthorizationController.Post(tvItemUserAuthorizationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet3); CreatedNegotiatedContentResult <TVItemUserAuthorization> tvItemUserAuthorizationRet3 = jsonRet3 as CreatedNegotiatedContentResult <TVItemUserAuthorization>; Assert.IsNotNull(tvItemUserAuthorizationRet3); BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult; Assert.IsNull(badRequest3); IHttpActionResult jsonRet4 = tvItemUserAuthorizationController.Delete(tvItemUserAuthorizationRet, LanguageRequest.ToString()); Assert.IsNotNull(jsonRet4); OkNegotiatedContentResult <TVItemUserAuthorization> tvItemUserAuthorizationRet4 = jsonRet4 as OkNegotiatedContentResult <TVItemUserAuthorization>; Assert.IsNotNull(tvItemUserAuthorizationRet4); BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult; Assert.IsNull(badRequest4); } } }
/// <summary> /// Validate function for all TVItemUserAuthorizationService commands /// </summary> /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param> /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param> /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns> private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType) { string retStr = ""; Enums enums = new Enums(LanguageRequest); TVItemUserAuthorization tvItemUserAuthorization = validationContext.ObjectInstance as TVItemUserAuthorization; tvItemUserAuthorization.HasErrors = false; if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete) { if (tvItemUserAuthorization.TVItemUserAuthorizationID == 0) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVItemUserAuthorizationID"), new[] { "TVItemUserAuthorizationID" })); } if (!(from c in db.TVItemUserAuthorizations select c).Where(c => c.TVItemUserAuthorizationID == tvItemUserAuthorization.TVItemUserAuthorizationID).Any()) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItemUserAuthorization", "TVItemUserAuthorizationID", tvItemUserAuthorization.TVItemUserAuthorizationID.ToString()), new[] { "TVItemUserAuthorizationID" })); } } TVItem TVItemContactTVItemID = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.ContactTVItemID select c).FirstOrDefault(); if (TVItemContactTVItemID == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "ContactTVItemID", tvItemUserAuthorization.ContactTVItemID.ToString()), new[] { "ContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemContactTVItemID.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "ContactTVItemID", "Contact"), new[] { "ContactTVItemID" })); } } TVItem TVItemTVItemID1 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID1 select c).FirstOrDefault(); if (TVItemTVItemID1 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID1", tvItemUserAuthorization.TVItemID1.ToString()), new[] { "TVItemID1" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID1.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID1", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID1" })); } } if (tvItemUserAuthorization.TVItemID2 != null) { TVItem TVItemTVItemID2 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID2 select c).FirstOrDefault(); if (TVItemTVItemID2 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID2", (tvItemUserAuthorization.TVItemID2 == null ? "" : tvItemUserAuthorization.TVItemID2.ToString())), new[] { "TVItemID2" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID2.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID2", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID2" })); } } } if (tvItemUserAuthorization.TVItemID3 != null) { TVItem TVItemTVItemID3 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID3 select c).FirstOrDefault(); if (TVItemTVItemID3 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID3", (tvItemUserAuthorization.TVItemID3 == null ? "" : tvItemUserAuthorization.TVItemID3.ToString())), new[] { "TVItemID3" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID3.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID3", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID3" })); } } } if (tvItemUserAuthorization.TVItemID4 != null) { TVItem TVItemTVItemID4 = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.TVItemID4 select c).FirstOrDefault(); if (TVItemTVItemID4 == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "TVItemID4", (tvItemUserAuthorization.TVItemID4 == null ? "" : tvItemUserAuthorization.TVItemID4.ToString())), new[] { "TVItemID4" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Root, TVTypeEnum.Address, TVTypeEnum.Area, TVTypeEnum.ClimateSite, TVTypeEnum.Contact, TVTypeEnum.Country, TVTypeEnum.Email, TVTypeEnum.File, TVTypeEnum.HydrometricSite, TVTypeEnum.Infrastructure, TVTypeEnum.MikeScenario, TVTypeEnum.MikeSource, TVTypeEnum.Municipality, TVTypeEnum.MWQMSite, TVTypeEnum.PolSourceSite, TVTypeEnum.Province, TVTypeEnum.Sector, TVTypeEnum.Subsector, TVTypeEnum.Tel, TVTypeEnum.TideSite, TVTypeEnum.WasteWaterTreatmentPlant, TVTypeEnum.LiftStation, TVTypeEnum.Spill, TVTypeEnum.BoxModel, TVTypeEnum.VisualPlumesScenario, TVTypeEnum.OtherInfrastructure, TVTypeEnum.MWQMRun, TVTypeEnum.MeshNode, TVTypeEnum.WebTideNode, TVTypeEnum.SamplingPlan, TVTypeEnum.SeeOtherMunicipality, TVTypeEnum.LineOverflow, TVTypeEnum.MapInfo, TVTypeEnum.MapInfoPoint, }; if (!AllowableTVTypes.Contains(TVItemTVItemID4.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "TVItemID4", "Root,Address,Area,ClimateSite,Contact,Country,Email,File,HydrometricSite,Infrastructure,MikeScenario,MikeSource,Municipality,MWQMSite,PolSourceSite,Province,Sector,Subsector,Tel,TideSite,WasteWaterTreatmentPlant,LiftStation,Spill,BoxModel,VisualPlumesScenario,OtherInfrastructure,MWQMRun,MeshNode,WebTideNode,SamplingPlan,SeeOtherMunicipality,LineOverflow,MapInfo,MapInfoPoint"), new[] { "TVItemID4" })); } } } retStr = enums.EnumTypeOK(typeof(TVAuthEnum), (int?)tvItemUserAuthorization.TVAuth); if (!string.IsNullOrWhiteSpace(retStr)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "TVAuth"), new[] { "TVAuth" })); } if (tvItemUserAuthorization.LastUpdateDate_UTC.Year == 1) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" })); } else { if (tvItemUserAuthorization.LastUpdateDate_UTC.Year < 1980) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" })); } } TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == tvItemUserAuthorization.LastUpdateContactTVItemID select c).FirstOrDefault(); if (TVItemLastUpdateContactTVItemID == null) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", tvItemUserAuthorization.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" })); } else { List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>() { TVTypeEnum.Contact, }; if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType)) { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" })); } } retStr = ""; // added to stop compiling CSSPError if (retStr != "") // will never be true { tvItemUserAuthorization.HasErrors = true; yield return(new ValidationResult("AAA", new[] { "AAA" })); } }
// Post public TVItemUserAuthorizationModel PostAddTVItemUserAuthorizationDB(TVItemUserAuthorizationModel tvItemUserAuthorizationModel) { string retStr = TVItemUserAuthorizationModelOK(tvItemUserAuthorizationModel); 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)); } if (contactOK.ContactTVItemID == tvItemUserAuthorizationModel.ContactTVItemID) { return(ReturnError(ServiceRes.CantSetOwnAuthorization)); } TVItemUserAuthorization tvItemUserAuthorizationExist = GetTVItemUserAuthorizationWithContactTVItemIDTVItemID1TVItemID2TVItemID3TVItemID4DB(tvItemUserAuthorizationModel.ContactTVItemID, tvItemUserAuthorizationModel.TVItemID1, tvItemUserAuthorizationModel.TVItemID2, tvItemUserAuthorizationModel.TVItemID3, tvItemUserAuthorizationModel.TVItemID4); if (tvItemUserAuthorizationExist != null) { return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.TVItemUserAuthorization))); } TVItemUserAuthorization tvItemUserAuthorizationNew = new TVItemUserAuthorization(); retStr = FillTVItemUserAuthorization(tvItemUserAuthorizationNew, tvItemUserAuthorizationModel, contactOK); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } using (TransactionScope ts = new TransactionScope()) { db.TVItemUserAuthorizations.Add(tvItemUserAuthorizationNew); retStr = DoAddChanges(); if (!string.IsNullOrWhiteSpace(retStr)) { return(ReturnError(retStr)); } LogModel logModel = _LogService.PostAddLogForObj("TVItemUserAuthorizations", tvItemUserAuthorizationNew.TVItemUserAuthorizationID, LogCommandEnum.Add, tvItemUserAuthorizationNew); if (!string.IsNullOrWhiteSpace(logModel.Error)) { return(ReturnError(logModel.Error)); } ts.Complete(); } return(GetTVItemUserAuthorizationModelWithTVItemUserAuthorizationIDDB(tvItemUserAuthorizationNew.TVItemUserAuthorizationID)); }
public TVItemUserAuthorizationTest() { tVItemUserAuthorization = new TVItemUserAuthorization(); tVItemUserAuthorizationExtraA = new TVItemUserAuthorizationExtraA(); tVItemUserAuthorizationExtraB = new TVItemUserAuthorizationExtraB(); }