public LeadDetailsModel Creation(LeadCreateModel leadModel) { // TODO: Resolve Usuario atual(Logado) var userId = 1; leadModel.CreatedById = userId; var lead = _mapper.Map <Lead>(leadModel); // TODO: Validator _leadValidator.Creation(lead); // TODO: Chama repository var leadRepository = _unitOfWork.GetRepository <ILeadRepository>(); var leadCreated = leadRepository.Create(lead); LeadDetailsModel leadDetailsModel = new LeadDetailsModel(); // TODO: Commit if (!_unitOfWork.Commit()) { leadDetailsModel.Erros = _mapper.Map <List <ErroModel> >(_notificationHandler.GetNotifications()); return(leadDetailsModel); } // TODO: Devolver objeto sucesso ou falha leadDetailsModel = _mapper.Map <LeadDetailsModel>(lead); return(leadDetailsModel); }
public ActionResult Post([FromBody] LeadCreateModel leadModel) { if (!ModelState.IsValid) { return(BadRequest()); } var leadDetailsModel = _leadService.Creation(leadModel); return(CreatedAtAction(nameof(Post), leadDetailsModel)); }
public async Task <Response> Create(LeadCreateModel leadCreateModel, ClaimsPrincipal user) { using (var context = _applicationDbContextFactory.Create()) { var User = await _userManager.FindByNameAsync(user.Identity.Name); var Lead = Mapper.Map <Lead>(leadCreateModel); if (!context.Check <Course>(leadCreateModel.CourseId)) { return new Response { Status = 500, Message = "Такого курса нет!" } } ; if (!context.Check <LeadStatus>(leadCreateModel.LeadStatusId)) { return new Response { Status = 500, Message = "Такого статуса нет!" } } ; if (!context.Check <City>(leadCreateModel.CityId)) { return new Response { Status = 500, Message = "Такого города нет!" } } ; if (context.Leads.Any(i => i.Id == Lead.Id)) { return new Response { Status = 500, Message = "Такой лид уже существует!" } } ; Lead.CreateDate = DateTime.Now; var Result = context.Leads.Add(Lead); context.SaveChanges(); context.LeadHistories.Add(new LeadHistory { Action = "Создание", LeadId = Result.Entity.Id, DateTime = DateTime.Now, UserId = User.Id }); context.SaveChanges(); return(new Response { Status = 100, Message = "Запрос успешно прошел." }); } }
public async Task CreateLead(LeadCreateModel leadModel) { if (!this.db.Leads.Any(a => a.Id == leadModel.Id)) { var lead = new Lead() { Name = leadModel.Name, PinCode = leadModel.PinCode, SubArea = leadModel.SubArea, Address = leadModel.Address, MobileNumber = leadModel.MobileNumber, Email = leadModel.Email }; await this.db.Leads.AddAsync(lead); await this.db.SaveChangesAsync(); } }
public async Task <ActionResult <LeadModel> > PostLead(LeadCreateModel model) { var campaign = DB.Campaigns.Find(model.Campaign_Id); var result = Check(campaign is Campaign, NotFound).OkNull() ?? Check(Operation.Create); if (result.Fail()) { return(result); } var entity = GetEntity(model); DB_TABLE.Add(entity); await DB.SaveChangesAsync(); Log(DB_TABLE.GetName(), Operation.Create, campaign.Id, GetModel(entity)); return(CreatedAtAction(nameof(GetLead), new { id = entity.Id }, GetModel(entity))); }
public async Task <IActionResult> Create([FromBody] LeadCreateModel lead) //AzureLead { await this.leadService.CreateLead(lead); return(Ok()); }
public async Task <ActionResult <Response> > Create(LeadCreateModel model) { return(await _leadService.Create(model, User)); }