/// <summary> /// Updates a subject. /// </summary> /// <param name="itemToSave">The item to save.</param> /// <param name="accountId">The account identifier.</param> /// <returns>The result.</returns> public ResultDto UpdateSubject(SubjectEditDto itemToSave, Guid?accountId) { ResultDto result = new ResultDto(); using (BzsEntityContainer ctx = this.CreateContainer()) { SubjectEntity entity = ctx.SubjectSet.FirstOrDefault(f => f.Id == itemToSave.Id); if (entity == null) { result.Error = "ERR-SUBJECT-NOT-EXISTS"; return(result); } if (entity.AccountId == null || entity.AccountId != accountId) { result.Error = "ERR-SUBJECT-ACCOUNT-INVALID"; return(result); } entity.Code = itemToSave.Code.Length > 10 ? itemToSave.Code.Substring(0, 9) : itemToSave.Code; entity.Caption = itemToSave.Caption.Length > 50 ? itemToSave.Caption.Substring(0, 49) : itemToSave.Caption; entity.ModDate = DateTime.Now; entity.ModUser = Environment.UserName; ctx.SaveChanges(); result.Success = true; } return(result); }
/// <summary> /// Updates a subject. /// </summary> /// <param name="itemToSave">The item to save.</param> /// <returns>The result.</returns> public ResultDto UpdateSubject(SubjectEditDto itemToSave) { this.SetResponseHeaderCacheExpiration(); AccountPassword credentials = this.GetCredentialsFromRequest(); AccountServerService accountService = new AccountServerService(); Guid accountId = accountService.GetAccountId(credentials.Account); SubjectServerService service = new SubjectServerService(); return(service.UpdateSubject(itemToSave, accountId)); }