Ejemplo n.º 1
0
 public IActionResult SaveLeadInfo([FromBody] LeadInformation lead)
 {
     try
     {
         foreach (var item in lead.ContactDetails)
         {
             if (string.IsNullOrEmpty(item.ContactNumber) || item == null)
             {
                 return(BadRequest("Contact number cannot be empty"));
             }
         }
         var res = _loanService.SaveLeadInformation(lead);
         if (res)
         {
             return(Ok("Lead created"));
         }
         else
         {
             return(Conflict("Same record already found"));
         }
     }
     catch (Exception)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
Ejemplo n.º 2
0
        public async Task <ActionResult <LeadInformation> > PostLeadInformation(LeadInformation leadInformation)
        {
            _context.LeadInformations.Add(leadInformation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLeadInformation", new { id = leadInformation.Id }, leadInformation));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutLeadInformation(int id, LeadInformation leadInformation)
        {
            if (id != leadInformation.Id)
            {
                return(BadRequest());
            }

            _context.Entry(leadInformation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeadInformationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 4
0
        bool ILoanLeadService.UpdateLeadInformation(LeadInformation lead)
        {
            try
            {
                string leadCmd                 = @"update LoanLead set LoanAmount = @LoanAmount,LeadSource = @LeadSource,CommunicationMode = @CommunicationMode,Status = @Status
                                where LeadId = @LeadId";
                string communicationcmd        = @"update ContactDetails set ContactType = @ContactType,ContactName = @ContactName,Dob = @Dob,Gender = @Gender,Email = @Email,ContactNumber =@ContactNumber
                                        where LeadId = @LeadId";
                List <ContactDetails> contacts = new List <ContactDetails>();
                var leadParam = new DynamicParameters();
                leadParam.Add("@LoanAmount", lead.LoanAmount);
                leadParam.Add("@LeadSource", lead.LeadSource);
                leadParam.Add("@CommunicationMode", lead.CommunicationMode);
                leadParam.Add("@Status", lead.Status);
                leadParam.Add("@leadId", dbType: DbType.Int32, direction: ParameterDirection.InputOutput);

                using (IDbConnection con = _connection)
                {
                    con.Open();
                    var updatedLead = con.Execute(leadCmd, leadParam);

                    foreach (var item in lead.ContactDetails)
                    {
                        contacts.Add(new ContactDetails {
                            LeadId        = item.LeadId,
                            ContactType   = item.ContactType,
                            ContactName   = item.ContactName,
                            Dob           = item.Dob,
                            Gender        = item.Gender,
                            Email         = item.Email,
                            ContactNumber = item.ContactNumber
                        });
                    }
                    var updatedContacts = con.Execute(communicationcmd, contacts);

                    con.Close();

                    if (updatedLead > 0 || updatedContacts > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        public bool SaveLeadInformation(LeadInformation lead)
        {
            try
            {
                string communicationcmd        = @"insert into ContactDetails(LeadId,ContactType,ContactName,Dob,Gender,Email,ContactNumber) values(@LeadId,@ContactType,@ContactName,@Dob,@Gender,@Email,@ContactNumber)";
                List <ContactDetails> contacts = new List <ContactDetails>();
                var leadParam = new DynamicParameters();
                leadParam.Add("@LoanAmount", lead.LoanAmount);
                leadParam.Add("@LeadSource", lead.LeadSource);
                leadParam.Add("@CommunicationMode", lead.CommunicationMode);
                leadParam.Add("@Status", lead.Status);
                leadParam.Add("@leadId", dbType: DbType.Int32, direction: ParameterDirection.InputOutput);

                using (IDbConnection con = _connection)
                {
                    con.Open();
                    var insertedLead   = con.Execute("dbo.[sp_saveLeadInfo]", leadParam, commandType: CommandType.StoredProcedure);
                    int insertedLeadId = leadParam.Get <int>("@leadId");

                    foreach (var item in lead.ContactDetails)
                    {
                        contacts.Add(new ContactDetails {
                            LeadId        = insertedLeadId,
                            ContactType   = item.ContactType,
                            ContactName   = item.ContactName,
                            Dob           = item.Dob,
                            Gender        = item.Gender,
                            Email         = item.Email,
                            ContactNumber = item.ContactNumber
                        });
                    }
                    var inesertedContacts = con.Execute(communicationcmd, contacts);

                    con.Close();

                    if (insertedLead > 0 && inesertedContacts > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        public IActionResult UpdateLeadInfo([FromBody] LeadInformation lead)
        {
            try
            {
                if (lead.LeadId <= 0)
                {
                    return(BadRequest("Lead id cannot be less than zero"));
                }
                var res = _loanService.UpdateLeadInformation(lead);

                if (res)
                {
                    return(Ok("Lead info updated"));
                }
                else
                {
                    return(NotFound($"Lead information not found for id:{lead.LeadId}"));
                }
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }