public string Save(EditCultureData model) { var oldCode = model.OldCode; if (_queries.GetCultures().Any(c => c.Code == model.Code && c.Code != oldCode)) { throw new RegoException("app:common.codeUnique"); } var username = _actorInfoProvider.Actor.UserName; using (var scope = CustomTransactionScope.GetTransactionScope()) { var culture = new Culture { Code = model.Code, CreatedBy = username, DateCreated = DateTimeOffset.UtcNow, Name = model.Name, NativeName = model.NativeName }; _brandRepository.Cultures.Add(culture); _brandRepository.SaveChanges(); _eventBus.Publish(new LanguageCreated(culture)); scope.Complete(); } return("app:language.created"); }
public string Edit(EditCultureData model) { var oldCode = model.OldCode; var culture = _brandRepository.Cultures.SingleOrDefault(c => c.Code == oldCode); if (culture == null) { throw new RegoException("app:common.invalidId"); } if (_queries.GetCultures().Any(c => c.Code == model.Code && c.Code != oldCode)) { throw new RegoException("app:common.codeUnique"); } var username = _actorInfoProvider.Actor.UserName; using (var scope = CustomTransactionScope.GetTransactionScope()) { culture.UpdatedBy = username; culture.DateUpdated = DateTimeOffset.UtcNow; culture.Name = model.Name; culture.NativeName = model.NativeName; _brandRepository.SaveChanges(); _eventBus.Publish(new LanguageUpdated(culture)); scope.Complete(); } return("app:language.updated"); }
public void ThenCultureDataIsSuccessfullySaved() { var data = new EditCultureData { Code = TestDataGenerator.GetRandomString(3), Name = TestDataGenerator.GetRandomString(), NativeName = TestDataGenerator.GetRandomString() }; var result = AdminApiProxy.SaveCulture(data); result.Should().NotBeNull(); result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK); }
public IHttpActionResult Save(EditCultureData data) { var newCulture = string.IsNullOrEmpty(data.OldCode); VerifyPermission(newCulture ? Permissions.Create : Permissions.Update, Modules.LanguageManager); if (!ModelState.IsValid) { return(Ok(ErrorResponse())); } try { var result = newCulture ? _cultureCommands.Save(data) : _cultureCommands.Edit(data); return(Ok(new { Result = "success", Data = result })); } catch (Exception e) { return(Ok(new { Result = "failed", Data = e.Message })); } }
public HttpResponseMessage SaveCulture(EditCultureData request) { return(WebClient.SecurePostAsJson <EditCultureData, HttpResponseMessage>(Token, _url + AdminApiRoutes.SaveCulture, request)); }