public void AddPurchase(ServiceRequestModel <PurchaseViewModel> serviceRequestModel) { var mapped = _mapper.Map <PurchaseViewModel, Purchase>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); mapped.CreatedDate = GeneralService.CurrentDate; mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; mapped.Step = 1; mapped.ProcessingStatus = ProcessingStatus.Pending; if (serviceRequestModel.LoginInfo.RoleId == new Guid(ApplicationConstants.AreaAdministratorRoleId) || serviceRequestModel.LoginInfo.RoleId == new Guid(ApplicationConstants.AssistantAreaAdministratorRoleId)) { mapped.BranchId = serviceRequestModel.Model.BranchId.Value; } else { mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.FirstOrDefault().Id; } _genericUnitOfWork.GetRepository <Purchase, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); var emails = _sharedService.GetPurchaseProcessorEmails(mapped.Id); SendEmailToFirstStep(emails, new AdminNotificationViewModel() { Date = mapped.CreatedDate.ToString("dd/MM/yyyy"), Sender = _sharedService.GetUserFullName(mapped.CreatedById), ProcessingType = mapped.ProcessingStatus.ToString(), Category = serviceRequestModel.Model.CategoryName, CategoryItem = serviceRequestModel.Model.CategoryItemName, PurchaseQuotations = serviceRequestModel.Model.Quotations, }); }