public IActionResult Put(Language entityModel) { //if (!ModelState.IsValid) // return BadRequest(); //get var language = _languageService.Get(entityModel.Id); if (language == null) { return(RespondFailure()); } language.Name = entityModel.Name; language.Published = entityModel.Published; language.LanguageCulture = entityModel.LanguageCulture; language.DisplayOrder = entityModel.DisplayOrder; language.FlagImageFileName = entityModel.FlagImageFileName; language.UniqueSeoCode = entityModel.UniqueSeoCode; //save it _languageService.Update(language); VerboseReporter.ReportSuccess("Sửa ngôn ngữ thành công", "put"); return(RespondSuccess(language)); }
public IHttpActionResult Post(EmailAccountEntityModel entityModel) { if (!ModelState.IsValid) { return(BadRequest()); } //create a new email account var emailAccount = new EmailAccount() { Id = entityModel.Id, Email = entityModel.Email, UserName = entityModel.UserName, FromName = entityModel.FromName, Host = entityModel.Host, UseSsl = entityModel.UseSsl, Port = entityModel.Port, UseDefaultCredentials = entityModel.UseDefaultCredentials, Password = _cryptographyService.Encrypt(entityModel.Password) }; //if this is the first account, we'll set it as default emailAccount.IsDefault = _emailAccountService.Count() == 0; //save it _emailAccountService.Insert(emailAccount); VerboseReporter.ReportSuccess("Successfully saved email account", "post_emailaccount"); return(RespondSuccess(new { EmailAccount = emailAccount.ToEntityModel() })); }
public IHttpActionResult Post(SettingEntityModel entityModel) { var setting = entityModel.Id == 0 ? new Setting() : _settingService.Get(entityModel.Id); if (setting == null) { return(NotFound()); } setting.GroupName = entityModel.GroupName; setting.Key = entityModel.Key; setting.Value = entityModel.Value; if (entityModel.Id == 0) { _settingService.Insert(setting); } else { _settingService.Update(setting); } VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess()); }
public IHttpActionResult Delete(int id) { //the users are automatically soft deletable. That means they won't be deleted actually. Instead the deleted flag is set to true _userService.Delete(x => x.Id == id); VerboseReporter.ReportSuccess("Successfully deleted the user", "delete"); return(RespondSuccess()); }
public IActionResult Put(NewsCategoryModel entityModel) { if (!ModelState.IsValid) { return(BadRequest()); } //get var newsCategory = _newsCategoryService.Get(entityModel.Id); if (newsCategory == null) { return(RespondFailure()); } newsCategory.Name = entityModel.Name; newsCategory.ParentId = entityModel.ParentId; newsCategory.Short = entityModel.Short; newsCategory.DisplayOrder = entityModel.DisplayOrder; //save it _newsCategoryService.Update(newsCategory); VerboseReporter.ReportSuccess("Sửa danh mục thành công", "put"); return(RespondSuccess(newsCategory)); }
public IHttpActionResult Login(LoginModel loginModel) { var redirect = false; if (loginModel == null || !ModelState.IsValid || !ShouldSignIn(loginModel.Email, loginModel.Password)) { VerboseReporter.ReportError("The email or password is invalid", "login"); return(RespondFailure()); } //sign in the current user var loginStatus = ApplicationContext.Current.SignIn(loginModel.Email, loginModel.Persist); if (loginStatus == LoginStatus.Success) { //update the last login date & ip address var currentUser = ApplicationContext.Current.CurrentUser; currentUser.LastLoginDate = DateTime.UtcNow; currentUser.LastLoginIpAddress = WebHelper.GetClientIpAddress(); _userService.Update(currentUser); VerboseReporter.ReportSuccess("Your login was successful", "login"); return(RespondSuccess(new { ReturnUrl = loginModel.ReturnUrl, User = ApplicationContext.Current.CurrentUser.ToModel(_mediaService, _mediaSettings, _followService, _friendService, _notificationService) })); } VerboseReporter.ReportError("The login attempt failed due to unknown error", "login"); return(RespondFailure()); }
public IHttpActionResult Post(MediaSettingsModel entityModel) { var mediaSettings = new MediaSettings() { SmallCoverPictureSize = entityModel.SmallCoverPictureSize, MediumCoverPictureSize = entityModel.MediumCoverPictureSize, OtherMediaSavePath = entityModel.OtherMediaSavePath, PictureSavePath = entityModel.PictureSavePath, VideoSavePath = entityModel.VideoSavePath, MediumProfilePictureSize = entityModel.MediumProfilePictureSize, SmallProfilePictureSize = entityModel.SmallProfilePictureSize, DefaultUserProfileImageUrl = entityModel.DefaultUserProfileImageUrl, DefaultUserProfileCoverUrl = entityModel.DefaultUserProfileCoverUrl, OtherMediaSaveLocation = entityModel.OtherMediaSaveLocation, PictureSaveLocation = entityModel.PictureSaveLocation, ThumbnailPictureSize = entityModel.ThumbnailPictureSize, MaximumFileUploadSizeForVideos = entityModel.MaximumFileUploadSizeForVideos, MaximumFileUploadSizeForDocuments = entityModel.MaximumFileUploadSizeForDocuments, MaximumFileUploadSizeForImages = entityModel.MaximumFileUploadSizeForImages }; _settingService.Save(mediaSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { MediaSettings = mediaSettings.ToModel() })); }
public IActionResult Put(MenuModel entityModel) { //if (!ModelState.IsValid) // return BadRequest(); //get var menu = _menuService.Get(entityModel.Id); if (menu == null) { return(RespondFailure()); } menu.Name = entityModel.Name; menu.Sequence = entityModel.Sequence; menu.ParentId = entityModel.ParentId; menu.Url = entityModel.Url; menu.PositionId = entityModel.PositionId; menu.Icon = entityModel.Icon; menu.Active = entityModel.Active; menu.ModifyDate = DateTime.Now; menu.ModifyBy = CurrentUser.Id; menu.NewWindow = entityModel.NewWindow; //save it _menuService.Update(menu); //var model = menu.ToModel(); SaveLocalizedValue(menu, entityModel); VerboseReporter.ReportSuccess("Sửa Menu thành công", "put"); return(RespondSuccess(entityModel)); }
public IActionResult Put(EmailAccount entityModel) { var emailAccount = _emailAccountService.FirstOrDefault(x => x.Id == entityModel.Id); //save it and respond emailAccount.DisplayName = entityModel.DisplayName; emailAccount.Host = entityModel.Host; emailAccount.Port = entityModel.Port; emailAccount.Email = entityModel.Email; emailAccount.Username = entityModel.Username; if (entityModel.Password.IsNotNullOrEmpty()) { // TODO encrypt password emailAccount.Password = entityModel.Password; // emailAccount.Password = _cryptographyService.Encrypt(entityModel.Password); } emailAccount.IsDefault = entityModel.IsDefault; _emailAccountService.Update(emailAccount); VerboseReporter.ReportSuccess("Sửa EmailAccount thành công", "post"); return(RespondSuccess(emailAccount)); }
public IActionResult Put([FromBody] CategoryPostModel entityModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //get var category = _categoryService.Get(entityModel.Id); if (category == null) { return(RespondFailure()); } category.Name = entityModel.Name; category.ParentCategoryId = entityModel.ParentCategoryId; category.Description = entityModel.Description; category.DisplayOrder = entityModel.DisplayOrder; category.Published = entityModel.Published; category.UpdatedOnUtc = DateTime.Now; //save it _categoryService.Update(category); VerboseReporter.ReportSuccess("Sửa danh mục thành công", "put"); return(RespondSuccess(category)); }
public IHttpActionResult Post(EmailTemplateEntityModel entityModel) { if (!ModelState.IsValid) { return(BadRequest()); } //create a new email template var emailTemplate = new EmailTemplate() { Id = entityModel.Id, AdministrationEmail = entityModel.AdministrationEmail, EmailAccountId = entityModel.EmailAccountId, IsMaster = entityModel.IsMaster, ParentEmailTemplateId = entityModel.ParentEmailTemplateId, Subject = entityModel.Subject, Template = entityModel.Template, TemplateName = entityModel.TemplateName, TemplateSystemName = entityModel.TemplateSystemName, IsSystem = false }; //save it _emailTemplateService.Insert(emailTemplate); VerboseReporter.ReportSuccess("Successfully saved email template", "post_emailtemplate"); return(RespondSuccess(new { EmailTemplate = emailTemplate.ToEntityModel() })); }
public IHttpActionResult Put(EmailTemplateEntityModel entityModel) { if (!ModelState.IsValid) { return(BadRequest()); } //get the account var emailTemplate = _emailTemplateService.Get(entityModel.Id); if (emailTemplate == null) { return(NotFound()); } emailTemplate.AdministrationEmail = entityModel.AdministrationEmail; emailTemplate.EmailAccountId = entityModel.EmailAccountId; emailTemplate.IsMaster = !emailTemplate.IsSystem && entityModel.IsMaster; //a system template can't be used as master emailTemplate.ParentEmailTemplateId = entityModel.ParentEmailTemplateId; emailTemplate.Subject = entityModel.Subject; emailTemplate.Template = entityModel.Template; emailTemplate.TemplateName = entityModel.TemplateName; //save it _emailTemplateService.Update(emailTemplate); VerboseReporter.ReportSuccess("Successfully updated email template", "put_emailtemplate"); return(RespondSuccess(new { EmailTemplate = emailTemplate.ToEntityModel() })); }
public IActionResult Put(NewsLetterSubscription entityModel) { if (!ModelState.IsValid) { return(BadRequest()); } //get var newsLetterSubscription = _newsLetterSubscriptionService.Get(entityModel.Id); if (newsLetterSubscription == null) { return(RespondFailure()); } newsLetterSubscription = entityModel; newsLetterSubscription.Email = entityModel.Email; newsLetterSubscription.Mobile = entityModel.Mobile; newsLetterSubscription.Name = entityModel.Name; newsLetterSubscription.Active = entityModel.Active; newsLetterSubscription.StatusId = entityModel.StatusId; //save it _newsLetterSubscriptionService.Update(newsLetterSubscription); VerboseReporter.ReportSuccess("Sửa thư đăng ký thành công", "put"); return(RespondSuccess(newsLetterSubscription)); }
protected virtual void UpdateLocales(NewsItem NewsItem, NewsItemModel entityModel) { if (entityModel.LanguageId <= 0) { return; } entityModel.Locales.Add(new NewsItemLocalizedModel() { LanguageId = entityModel.LanguageId, Name = entityModel.Name, }); foreach (var localized in entityModel.Locales) { #region LocalizedProperty _localizedPropertyService.SaveLocalizedValue <NewsItem>(NewsItem, n => n.Name, NewsItem.Name, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue <NewsItem>(NewsItem, n => n.Short, NewsItem.Short, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue <NewsItem>(NewsItem, n => n.Full, NewsItem.Full, localized.LanguageId); #endregion //search engine name //var seName = NewsItem.ValidateSeName(localized.SeName, localized.Name, false); //_urlRecordService.SaveSlug(NewsItem, seName, localized.LanguageId); } VerboseReporter.ReportSuccess("Sửa ngôn ngữ tin tức thành công", "put"); }
public IActionResult Post(Language model) { //save it _languageService.Insert(model); VerboseReporter.ReportSuccess("Tạo ngôn ngữ thành công", "post"); return(RespondSuccess(model)); }
public IActionResult Delete(int id) { if (id <= 0) { return(RespondFailure()); } _newsCategoryService.Delete(x => x.Id == id); VerboseReporter.ReportSuccess("Xóa danh mục thành công", "delete"); return(RespondSuccess()); }
public IHttpActionResult Post(SecuritySettingsModel entityModel) { var securitySettings = new SecuritySettings() { DefaultPasswordStorageFormat = entityModel.DefaultPasswordStorageFormat }; _settingService.Save(securitySettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { SecuritySettings = securitySettings.ToModel() })); }
public IHttpActionResult Post(DateTimeSettingsModel entityModel) { var dateTimeSettings = new DateTimeSettings() { DefaultTimeZoneId = entityModel.DefaultTimeZoneId }; _settingService.Save(dateTimeSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { DateTimeSettings = dateTimeSettings.ToModel() })); }
public IHttpActionResult Post(UrlSettingsModel entityModel) { var thirdPartySettings = new UrlSettings() { ActivationPageUrl = entityModel.ActivationPageUrl }; _settingService.Save(thirdPartySettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { ThirdPartySettings = thirdPartySettings.ToModel() })); }
public IHttpActionResult Post(UserSettingsModel entityModel) { var userSettings = new UserSettings() { AreUserNamesEnabled = entityModel.AreUserNamesEnabled, UserRegistrationDefaultMode = entityModel.UserRegistrationDefaultMode }; _settingService.Save(userSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { UserSettings = userSettings.ToModel() })); }
public IHttpActionResult Put(UserEntityPublicModel entityModel) { var user = _userService.Get(entityModel.Id); if (user == null) { return(NotFound()); } //check if the email has already been registered var emailUser = _userService.Get(x => x.Email == entityModel.Email, null).FirstOrDefault(); if (emailUser != null && emailUser.Id != user.Id) { VerboseReporter.ReportError("The email is already registered with another user", "post_user"); return(RespondFailure()); } //same for user name if (_userSettings.AreUserNamesEnabled) { var userNameUser = _userService.Get(x => x.UserName == entityModel.UserName, null).FirstOrDefault(); if (userNameUser != null && userNameUser.Id != user.Id) { VerboseReporter.ReportError("The username is already taken by another user", "post_user"); return(RespondFailure()); } } user.FirstName = entityModel.FirstName; user.LastName = entityModel.LastName; user.Email = entityModel.Email; user.DateUpdated = DateTime.UtcNow; user.Name = string.Concat(user.FirstName, " ", user.LastName); user.UserName = entityModel.UserName; _userService.Update(user); //any images to assign if (entityModel.CoverImageId != 0) { user.SetPropertyValue(PropertyNames.DefaultCoverId, entityModel.CoverImageId); } if (entityModel.ProfileImageId != 0) { user.SetPropertyValue(PropertyNames.DefaultPictureId, entityModel.ProfileImageId); } VerboseReporter.ReportSuccess("Successfully saved profile", "post_user"); return(RespondSuccess(new { User = user.ToEntityPublicModel(_mediaService, _mediaSettings) })); }
public IActionResult Post(NewsCategoryModel entityModel) { //if (!ModelState.IsValid) // return BadRequest(); var newsCategory = entityModel.ToEntity(); //save it _newsCategoryService.Insert(newsCategory); VerboseReporter.ReportSuccess("Tạo danh mục thành công", "post"); return(RespondSuccess(entityModel )); }
public IHttpActionResult Delete(int id) { var setting = _settingService.Get(id); if (setting == null) { VerboseReporter.ReportError("Setting not found", "delete_setting"); return(RespondFailure()); } _settingService.Delete(setting); VerboseReporter.ReportSuccess("Setting deleted successfully", "delete_setting"); return(RespondSuccess()); }
public IActionResult Put(EmailMessage entityModel) { var emailMessage = _emailService.FirstOrDefault(x => x.Id == entityModel.Id); //save it and respond //_emailService.Update(emailMessage); VerboseReporter.ReportSuccess("Sửa EmailMessage thành công", "post"); return(RespondSuccess(emailMessage)); }
protected virtual void InsertLocales(NewsItem newsItem, NewsItemModel newsItemModel) { if (newsItemModel.LanguageId <= 0) { return; } newsItemModel.Locales.Add(new NewsItemLocalizedModel() { LanguageId = newsItemModel.LanguageId, Name = newsItemModel.Name, }); foreach (var localized in newsItemModel.Locales) { //ILocalizedPropertyService.SaveLocalizedValue(NewsItem, // x => x.Name, // localized.Name, // localized.LanguageId); #region LocalizedProperty _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty() { EntityId = newsItem.Id, LanguageId = localized.LanguageId, LocaleKeyGroup = "NewsItem", LocaleKey = "title", LocaleValue = newsItem.Name }); _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty() { EntityId = newsItem.Id, LanguageId = localized.LanguageId, LocaleKeyGroup = "NewsItem", LocaleKey = "summary", LocaleValue = newsItem.Short }); _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty() { EntityId = newsItem.Id, LanguageId = localized.LanguageId, LocaleKeyGroup = "NewsItem", LocaleKey = "content", LocaleValue = newsItem.Full }); #endregion ////search engine name //var seName = NewsItem.ValidateSeName(localized.SeName, localized.Name, false); //_urlRecordService.SaveSlug(NewsItem, seName, localized.LanguageId); } VerboseReporter.ReportSuccess("Sửa ngôn ngữ tin tức thành công", "put"); }
public IHttpActionResult Login(LoginModel loginModel) { var redirect = false; if (loginModel == null || !ModelState.IsValid) { if (!ModelState.IsValid && loginModel != null) { redirect = loginModel.Redirect; } if (!redirect) { VerboseReporter.ReportError("The email or password is invalid", "login"); return(RespondFailure()); } return(RespondRedirect(Request.RequestUri)); } redirect = loginModel.Redirect; if (!ShouldSignIn(loginModel.Email, loginModel.Password)) { if (!redirect) { VerboseReporter.ReportError("The email or password is invalid", "login"); return(RespondFailure()); } return(RespondRedirect(Request.RequestUri)); } //sign in the current user var loginStatus = ApplicationContext.Current.SignIn(loginModel.Email, loginModel.Persist); if (loginStatus == LoginStatus.Success) { if (!redirect) { VerboseReporter.ReportSuccess("Your login was successful", "login"); return(RespondSuccess(new { ReturnUrl = loginModel.ReturnUrl })); } return(RespondRedirect(loginModel.ReturnUrl)); } if (!redirect) { VerboseReporter.ReportError("The login attempt failed due to unknown error", "login"); return(RespondFailure()); } return(RespondRedirect(Request.RequestUri)); }
protected virtual void SaveLocalizedValue(Menu service, MenuModel entityModel) { if (entityModel.LanguageId <= 0) { return; } _localizedPropertyService.SaveLocalizedValue(service, x => x.Name, entityModel.Name, entityModel.LanguageId); VerboseReporter.ReportSuccess("Sửa ngôn ngữ thành công", "put"); }
public IActionResult Delete(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id <= 0) { return(RespondFailure()); } _categoryService.Delete(x => x.Id == id); VerboseReporter.ReportSuccess("Xóa danh mục thành công", "delete"); return(RespondSuccess()); }
public IActionResult Delete(int id) { if (id <= 0) { return(BadRequest()); } var emailMessage = _emailService.FirstOrDefault(x => x.Id == id); _emailService.Delete(emailMessage); VerboseReporter.ReportSuccess("Xóa EmailMessage thành công", "delete"); return(RespondSuccess()); }
public IHttpActionResult Post(ThirdPartySettingsModel entityModel) { var thirdPartySettings = new ThirdPartySettings() { EchonestApiKey = entityModel.EchonestApiKey, SevenDigitalOAuthConsumerKey = entityModel.SevenDigitalOAuthConsumerKey, SevenDigitalOAuthConsumerSecret = entityModel.SevenDigitalOAuthConsumerSecret, SevenDigitalPartnerId = entityModel.SevenDigitalPartnerId }; _settingService.Save(thirdPartySettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { ThirdPartySettings = thirdPartySettings.ToModel() })); }