Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public ActionResult Post([FromBody] LeadCreateModel leadModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var leadDetailsModel = _leadService.Creation(leadModel);

            return(CreatedAtAction(nameof(Post), leadDetailsModel));
        }
Exemplo n.º 3
0
        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 = "Запрос успешно прошел."
                });
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
        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)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([FromBody] LeadCreateModel lead) //AzureLead
        {
            await this.leadService.CreateLead(lead);

            return(Ok());
        }
Exemplo n.º 7
0
 public async Task <ActionResult <Response> > Create(LeadCreateModel model)
 {
     return(await _leadService.Create(model, User));
 }