public void ReadAllAdminNotifications(ERole role) { var notis = _context.AdminNotifications.Where(x => x.ToRole.Equals(role) && x.IsRead == false).ToList(); notis.ForEach(n => { n.IsRead = true; }); _context.SaveChanges(); }
public void DeleteById(int id) { var form = _context.complaintFormModels.FirstOrDefault(f => f.Id == id); try { _context.complaintFormModels.Remove(form); _context.SaveChanges(); } catch (Exception ex) { _logger.LogError("Can't remove form by id or save database", ex); } }
public async Task <IActionResult> CompanyRegistration(CompanyRegistartionViewModel model) { if (ModelState.IsValid) { var user = _mapper.MapCompanyRegistartionViewModelToApplicationUser(model); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!_roleManager.Roles.Any(x => x.Name == "Client")) { var role = new IdentityRole { Name = ERole.Client.ToString() }; await _roleManager.CreateAsync(role); } await _userManager.AddToRoleAsync(user, ERole.Client.ToString()); var noti = new ClientNotifications { CreatedDate = DateTime.Now, ToClientId = user.Id, FromRole = ERole.Admin, IsRead = false, NotiBody = "Hello " + user.CompanyName + " in our system!", NotiHeader = "Welcome ;)" }; try { _context.ClientNotifications.Add(noti); _context.SaveChanges(); } catch (Exception ex) { _logger.LogError("Error within saveing notification after registration", ex); } return(RedirectToAction("Success", "Success")); } else { _logger.LogWarning("Can't create Company user, something wrong with User Identity"); return(RedirectToAction("Error", "Error")); } } else { _logger.LogWarning("While creating user occur invalid model"); return(View(model)); } }
public void SaveToDatabase(Contact contactModel) { context.ContactMessages.Add(contactModel); context.SaveChanges(); }
public void AddInvoice(InvoiceData invoiceData) { _context.InvoiceData.Add(invoiceData); _context.SaveChanges(); }
public void AddNewTaskForEmployee(TaskForEmployee taskForEmployee) { _context.TaskForEmployee.Add(taskForEmployee); _context.SaveChanges(); }
public void AddEmployeeTask(EmployeeTask empTask) { _context.EmployeeTasks.Add(empTask); _context.SaveChanges(); }