private async Task <IActionResult> CreateUpdateSystemMessage(SystemMessageModel model, bool update) { if (model.DisplayDate.Start > model.DisplayDate.End) { model.SystemMessageTypeValue = EnumHelper.Parse <SystemMessageType>(model.SystemMessageType.SelectedItem.Value); ModelState.AddModelError($"{nameof(model.DisplayDate)}.{nameof(model.DisplayDate.Start)}", "Visningsdatum för nyheten är fel. Från och med datum kan inte vara större än till och med datum."); } else { if (update) { var sysMessage = await _dbContext.SystemMessages.GetSystemMessageById(model.SystemMessageId); sysMessage.Update(_clock.SwedenNow, User.GetUserId(), User.TryGetImpersonatorId(), model.DisplayDate.Start.ToDateTimeOffsetSweden(), model.DisplayDate.End.ToDateTimeOffsetSweden(), model.SystemMessageHeader, model.SystemMessageText, EnumHelper.Parse <SystemMessageType>(model.SystemMessageType.SelectedItem.Value), model.DisplayedForUserTypeGroup); } else { var sysMessage = new SystemMessage(); sysMessage.Create(_clock.SwedenNow, User.GetUserId(), User.TryGetImpersonatorId(), model.DisplayDate.Start.ToDateTimeOffsetSweden(), model.DisplayDate.End.ToDateTimeOffsetSweden(), model.SystemMessageHeader, model.SystemMessageText, EnumHelper.Parse <SystemMessageType>(model.SystemMessageType.SelectedItem.Value), model.DisplayedForUserTypeGroup); await _dbContext.AddAsync(sysMessage); } await _dbContext.SaveChangesAsync(); return(RedirectToAction("List")); } return(View(model)); }
public async Task <ActionResult> Create(CustomerUnitModel model) { if (ModelState.IsValid) { if (!IsUniqueName(model.Name)) { ModelState.AddModelError(nameof(model.Name), $"Namnet används redan för en annan enhet för denna myndighet"); } else if (!_userService.IsUniqueEmail(model.Email)) { ModelState.AddModelError(nameof(model.Email), $"E-postadressen används redan i tjänsten"); } else { int?customerId = User.TryGetCustomerOrganisationId(); var unit = new CustomerUnit(); unit.Create(_clock.SwedenNow, User.GetUserId(), User.TryGetImpersonatorId(), User.GetCustomerOrganisationId(), model.Name, model.Email, model.LocalAdministrator); await _userService.LogCustomerUnitUserUpdateAsync(model.LocalAdministrator, User.GetUserId(), User.TryGetImpersonatorId()); await _dbContext.AddAsync(unit); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(View), new { id = unit.CustomerUnitId })); } } return(View(model)); }
public async Task LogCreateAsync(int userId, int?createdById = null, int?impersonatingcreatorId = null) { await _dbContext.AddAsync(new UserAuditLogEntry { LoggedAt = _clock.SwedenNow, UpdatedByUserId = createdById, UpdatedByImpersonatorId = impersonatingcreatorId, UserChangeType = UserChangeType.Created, UserId = userId }); await _dbContext.SaveChangesAsync(); }
private async Task <IActionResult> CreateUpdateFaq(FaqModel model, bool update) { Faq faq = new Faq(); var displayForRoles = model.DisplayForRoles.SelectedItems.Select(r => EnumHelper.Parse <DisplayUserRole>(r.Value)); if (update) { var faqDisplayUserRolesWithFaq = await _dbContext.FaqDisplayUserRole.GetFaqWithFaqDisplayUserRolesByFaqId(model.FaqId).ToListAsync(); faq = faqDisplayUserRolesWithFaq.Select(f => f.Faq).First(); faq.Update(_clock.SwedenNow, User.GetUserId(), model.IsDisplayed, model.Question, model.Answer, displayForRoles); } else { faq.Create(_clock.SwedenNow, User.GetUserId(), model.IsDisplayed, model.Question, model.Answer, displayForRoles); await _dbContext.AddAsync(faq); } await _dbContext.SaveChangesAsync(); return(RedirectToAction("List")); }
public async Task <ActionResult> Create(InterpreterModel model) { if (ModelState.IsValid) { if (!_interpreterService.IsUniqueOfficialInterpreterId(model.OfficialInterpreterId, User.GetBrokerId())) { ModelState.AddModelError(nameof(model.OfficialInterpreterId), $"Er förmedling har redan registrerat en tolk med detta tolknummer (Kammarkollegiets) i tjänsten."); } else { InterpreterBroker interpreter = new InterpreterBroker(User.GetBrokerId()); model.UpdateInterpreter(interpreter); await _dbContext.AddAsync(interpreter); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(List), new InterpreterListModel { Message = "Ny tolk har skapats" })); } } return(View(model)); }
public async Task <InterpreterBroker> GetInterpreter(int interpreterId, InterpreterInformation interpreterInformation, int brokerId) { NullCheckHelper.ArgumentCheckNull(interpreterInformation, nameof(GetInterpreter), nameof(OrderService)); if (interpreterId == Constants.NewInterpreterId) { if (!IsUniqueOfficialInterpreterId(interpreterInformation.OfficialInterpreterId, brokerId)) { throw new ArgumentException("Er förmedling har redan registrerat en tolk med detta tolknummer (Kammarkollegiets) i tjänsten.", nameof(interpreterId)); } var interpreter = new InterpreterBroker( interpreterInformation.FirstName, interpreterInformation.LastName, brokerId, interpreterInformation.Email, interpreterInformation.PhoneNumber, interpreterInformation.OfficialInterpreterId ); await _dbContext.AddAsync(interpreter); return(interpreter); } return(await _dbContext.InterpreterBrokers.GetInterpreterBrokerById(interpreterId)); }