public IActionResult Delete(int id) { var _author = _authorService.Get(id); var _articles = _articleService.Search(x => x.AuthorId == _author.AuthorId); if (_articles.Count() > 0) { foreach (var _article in _articles) { _article.AuthorId = default; _articleService.Update(_article); } } try { _logger.Log(Niche.Core.Enums.LogLevel.INFORMATION, $"Delete: {_author.ToJson()} on {DateTime.UtcNow} UTC time"); _authorService.Delete(_author); return(Ok(new { check = true, message = "Author has been deleted successfully" })); } catch (Exception ex) { _logger.Log(Niche.Core.Enums.LogLevel.ERROR, ex.Message + ex.InnerException != null ? $" ,InnerException: {ex.InnerException.Message}" : ""); return(Ok(new { check = false, message = "Failed, try again" })); } }
public IActionResult Delete(int id) { var _article = _articleService.Get(id); try { _logger.Log(Niche.Core.Enums.LogLevel.INFORMATION, $"Delete: {_article.ToJson()} on {DateTime.UtcNow} UTC time"); _articleService.Delete(_article); return(Ok(new { check = true, message = "Article has been deleted successfully" })); } catch (Exception ex) { _logger.Log(Niche.Core.Enums.LogLevel.ERROR, ex.Message + ex.InnerException != null ? $" ,InnerException: {ex.InnerException.Message}" : ""); return(Ok(new { check = false, message = "Failed, try again" })); } }
public IActionResult DeleteAbout(int id) { var about = _aboutService.Get(id); if (about.IsSelected) { return(Ok(new { check = false, message = "Please, this about is active, first set another as active then delete." })); } try { _logger.Log(Niche.Core.Enums.LogLevel.INFORMATION, $"Delete: {about.ToJson()} on {DateTime.UtcNow} UTC time"); _aboutService.Delete(about); return(Ok(new { check = true, message = "About text has been deleted successfully" })); } catch (Exception ex) { _logger.Log(Niche.Core.Enums.LogLevel.ERROR, ex.Message + ex.InnerException != null ? $" ,InnerException: {ex.InnerException.Message}" : ""); return(Ok(new { check = false, message = "Failed, try again" })); } }
public async Task <IActionResult> Register(RegisterViewModel model) { if (!ModelState.IsValid) { model.Message = "Fill in all the fields"; return(View(model)); } var accounts = _accountService.SearchQ(x => x.Email == model.Email) .ToList(); if (accounts.Count > 0) { model.Message = "Email not avaible"; return(View(model)); } if (model.Password != model.RepPassword) { model.Message = "Paswords not matching"; return(View(model)); } model.Password = model.Password.ToSHA256(); var account = new Account { Id = Support.Id, Email = model.Email, Password = model.Password }; account = await _accountService.Add(account); if (account == null) { model.Message = "Registration failed"; return(View(model)); } var user = new User { Id = Support.Id, AccountId = account.Id, FirstName = model.FirstName, LastName = model.LastName }; user = await _userService.Add(user); if (user == null) { await _accountService.Delete(account); model.Message = "Registration failed"; return(View(model)); } await RegisterClaimsAsync(user); return(RedirectToAction("interim", "home")); }