public IActionResult Index(AddEntityDto model) { //todo: check all required attribute if (ModelState.IsValid) { var contentType = _db.ContentTypes .Include(t => t.Attrs) .FirstOrDefault(t => t.Id == model.ContentTypeId); if (contentType == null) { //todo: to log return(NotFound()); } if (!AllAttrsExists(model.Attrs, contentType)) { //todo: to log return(NotFound()); } var content = new Entity { EntityTypeId = model.ContentTypeId, AttrValues = model.Attrs.Select(CreateAttribute).ToList() }; _db.Content.Add(content); _db.SaveChanges(); return(RedirectToAction(nameof(Index), new { id = model.ContentTypeId })); } return(View(model)); }
private void LoginAttempt(User user) { // lock user if he makes too many login attempts var attemptCount = CommonSettings.FailedLoginAttemptLimit; var attemptMinute = CommonSettings.AttemptMinute; if (user.FailedLoginAttemptDateTime == null || user.FailedLoginAttemptDateTime < DateTime.UtcNow.AddMinutes(-attemptMinute)) { user.FailedLoginAttemptDateTime = DateTime.UtcNow; user.FailedLoginAttemptCounter = 1; _db.SaveChanges(); ModelState.AddModelError("", ChooseMessageForUser(user, attemptCount)); } else { user.FailedLoginAttemptCounter++; if (user.FailedLoginAttemptCounter == attemptCount && user.IsRegistrationApproved()) { user.RegistrationStatus = UserExt.LockedStatus; //todo: _emailService.SendInvalidLoginAttemptsResetPasswordEmail(user); ModelState.AddModelError("", string.Format(Get5FailedLoginAttemptsMessage(), attemptCount)); } else { ModelState.AddModelError("", ChooseMessageForUser(user, attemptCount)); } _db.SaveChanges(); } }
public IActionResult Edit(EditUserModel model) { if (ModelState.IsValid) { var user = _db.Users .FirstOrDefault(u => u.Id == model.Id); if (user == null) { return(NotFound()); } if (_db.Users.Any(u => u.Email == model.Email && u.Id != model.Id)) { ModelState.AddModelError("Email", "Пользователь с таким Email уже существует."); return(View(model)); } user.Email = model.Email; if (model.Password != PasswordHelper.SixAsterix) { PasswordHelper.SetPasswordHashed(user, model.Password); } _db.SaveChanges(); return(View()); } return(View(model)); }
public IActionResult Index(EditDictionaryDto model) { if (ModelState.IsValid) { var dictionary = new Dictionary { Name = model.Name }; _db.Dictionaries.Add(dictionary); _db.SaveChanges(); return(View(nameof(Edit), DtoHelper.GeEditDictionaryDto(dictionary))); } return(View(model)); }
public IActionResult Index(CreateContentTypeModel model) { if (ModelState.IsValid) { var contentType = new EntityType { Name = model.Name }; _db.ContentTypes.Add(contentType); _db.SaveChanges(); var editModel = DtoHelper.GetEditContentTypeModel(contentType); return(View(nameof(Edit), editModel)); } return(View(model)); }
public IActionResult Index(SettingsDto settingsDto) { if (ModelState.IsValid) { var settings = _db.ApplicationSettings.FirstOrDefault(); if (settings != null) { settings.NotificationRedirectionEmail = settingsDto.NotificationRedirectionEmail; } else { _db.ApplicationSettings.Add(new ApplicationSettings { NotificationRedirectionEmail = settingsDto.NotificationRedirectionEmail }); } _db.SaveChanges(); } return(View(settingsDto)); }
public string Create(Notification notification) { try { if (notification == null || string.IsNullOrEmpty(notification.Email) || string.IsNullOrEmpty(notification.Name) || string.IsNullOrEmpty(notification.Message)) { return("Error. Incorrect form data."); } notification.Date = DateTime.UtcNow.AddHours(4);//Saratov time; _db.Notifications.Add(notification); _db.SaveChanges(); _emailService.SendEmail(notification); return("success"); } catch (Exception ex) { //todo: use logger return("Error." + ex.Message); } }
public IActionResult Notification(int?id) { if (id == null || id < 1) { return(NotFound()); } var model = _context.Notifications.FirstOrDefault(n => n.Id == id); if (model == null) { return(NotFound()); } if (model.Status == NotificationStatus.New) { model.Status = NotificationStatus.Viewed; _context.SaveChanges(); } return(View(model)); }