/// <summary> /// Add agreement /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual async Task <ResultModel <Guid> > AddAgreementAsync(AddAgreementViewModel model) { if (model == null) { return(new InvalidParametersResultModel <Guid>()); } var contactRequest = await _contactService.GetContactByIdAsync(model.ContactId); if (contactRequest.IsSuccess) { if (contactRequest.Result.OrganizationId != model.OrganizationId) { return new ResultModel <Guid> { IsSuccess = false, Errors = new List <IErrorModel> { new ErrorModel { Message = "The organization does not have this contact " } } } } ; } var agreement = _mapper.Map <Agreement>(model); var existAgreement = _context.Agreements.Where(x => string.Equals(x.Name, agreement.Name, StringComparison.CurrentCultureIgnoreCase)); if (existAgreement.Any()) { var version = await existAgreement.CountAsync(); agreement.Name += " (" + version + ")"; } _context.Agreements.Add(agreement); var result = await _context.PushAsync(); if (result.IsSuccess) { await _notify.SendNotificationAsync(new List <Guid> { agreement.UserId }, new Notification { Content = $"Add agreement {agreement?.Name}", Subject = "Info", NotificationTypeId = NotificationType.Info }); } return(result.Map <Guid>(agreement.Id)); }
/// <summary> /// Add product /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual async Task <ResultModel <Guid> > AddProductAsync(AddProductViewModel model) { if (model == null) { return(new InvalidParametersResultModel <Guid>()); } var product = _mapper.Map <Product>(model); _context.Products.Add(product); var result = await _context.PushAsync(); return(new ResultModel <Guid> { IsSuccess = result.IsSuccess, Errors = result.Errors, Result = product.Id }); }
/// <summary> /// Add new lead /// </summary> /// <param name="model"></param> /// <returns></returns> public virtual async Task <ResultModel <Guid> > AddLeadAsync([Required] AddLeadViewModel model) { if (model == null) { return(new InvalidParametersResultModel <Guid>()); } var lead = _mapper.Map <Lead>(model); var leadBd = await _context.Leads.FirstOrDefaultAsync(x => x.PipeLineId == model.PipeLineId && x.Name.Trim().ToLower().Equals(model.Name.Trim().ToLower())); if (leadBd != null) { return new ResultModel <Guid> { IsSuccess = false, Errors = new List <IErrorModel> { new ErrorModel { Message = "Lead [" + leadBd.Name + "] exist" } } } } ; await _context.Leads.AddAsync(lead); var addLeadResult = await _context.PushAsync(); return(addLeadResult.Map <Guid>(lead.Id)); }