//[AdminAuthorize(PermissionType.Customers)] public async Task<Result<CustomerNoteModel>> CreateCustomerNotePrototype() { var toReturn = new CustomerNoteModel() { Priority = CustomerNotePriority.NormalPriority, DateCreated = DateTime.Now, DateEdited = DateTime.Now, }; var sUserId = _userManager.GetUserId(User); int userId; if (Int32.TryParse(sUserId, out userId)) { var adminProfileCondition = new AdminProfileQuery().WithId(userId); var adminProfile = (await _adminProfileService.QueryAsync(adminProfileCondition)).FirstOrDefault(); if (adminProfile != null) { toReturn.IdEditedBy = userId; toReturn.EditedBy = adminProfile.AgentId; toReturn.IdAddedBy = userId; toReturn.AddedBy = adminProfile.AgentId; } } return toReturn; }
public async Task PrepareCustomerNotes(CustomerDynamic dynamic, AddUpdateCustomerModel model) { var noteIds = dynamic.CustomerNotes.Where(x => x.IdEditedBy.HasValue).Select(x => x.IdEditedBy.Value).ToList(); noteIds.AddRange(dynamic.CustomerNotes.Where(x => x.IdAddedBy.HasValue).Select(x => x.IdAddedBy.Value).ToList()); var adminProfileCondition = new AdminProfileQuery().IdInRange(noteIds); var adminProfiles = await _adminProfileService.QueryAsync(adminProfileCondition); foreach (var customerNote in model.CustomerNotes) { customerNote.EditedBy = adminProfiles.SingleOrDefault( y => y.Id == dynamic.CustomerNotes.Single(z => z.Id == customerNote.Id).IdEditedBy)? .AgentId; customerNote.AddedBy = adminProfiles.SingleOrDefault( y => y.Id == dynamic.CustomerNotes.Single(z => z.Id == customerNote.Id).IdAddedBy)? .AgentId; } model.CustomerNotes = model.CustomerNotes.OrderByDescending(x => x.DateEdited).ToList(); }