public static int validateJobTitleId(string pJobTitleDescription)
        {
            try
            {
                using (DB_FleetServiceEntities db = new DB_FleetServiceEntities()) {
                    if (pJobTitleDescription.Trim() != "")
                    {
                        var jobTitle = db.JobTitlesClient.Where(jt => jt.jtcl_description.ToUpper() == pJobTitleDescription.ToUpper()).FirstOrDefault();

                        if (jobTitle == null)
                        {
                            JobTitlesClient job = new JobTitlesClient();
                            job.jtcl_description = pJobTitleDescription.ToUpper();
                            job.jtcl_state       = true;
                            db.JobTitlesClient.Add(job);
                            db.SaveChanges();

                            jobTitle = db.JobTitlesClient.Where(jt => jt.jtcl_description.ToUpper() == pJobTitleDescription.ToUpper()).FirstOrDefault();
                        }
                        return(jobTitle.jtcl_id);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
예제 #2
0
        public IHttpActionResult validateJobTitle(JobTitleViewModel pJobTitle)
        {
            try
            {
                using (BDRAEntities db = new BDRAEntities()) {
                    JobTitleViewModel jobTitle;

                    jobTitle = db.JobTitlesClient.Where(j => j.jtcl_description.ToUpper() == pJobTitle.description.ToUpper())
                               .Select(jt => new JobTitleViewModel {
                        id = jt.jtcl_id, description = jt.jtcl_description
                    })
                               .FirstOrDefault();
                    if (jobTitle == null)
                    {
                        JobTitlesClient jt = new JobTitlesClient();
                        jt.jtcl_description = pJobTitle.description;
                        jt.jtcl_state       = true;
                        db.JobTitlesClient.Add(jt);
                        db.SaveChanges();
                    }

                    var jtcl = db.JobTitlesClient.Where(j => j.jtcl_description.ToUpper() == pJobTitle.description.ToUpper())
                               .Select(jt => new JobTitleViewModel {
                        id = jt.jtcl_id, description = jt.jtcl_description
                    })
                               .FirstOrDefault();



                    return(Ok(jtcl));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));

                throw;
            }
        }
예제 #3
0
        public List <ContactViewModel> validateDataContact(List <string> lsData, string separator)
        {
            String            sline           = "--------------------------------------------------------------------------";
            var               lsContacts      = new List <ContactViewModel>();
            int               cont            = 0;
            ClientViewModel   clientByContact = new ClientViewModel();
            JobTitleViewModel jobTitle        = new JobTitleViewModel();
            BranchViewModel   branchByContact = new BranchViewModel();

            string sDocumentByClient = "";
            string sNameByContact    = "";
            string sJobTitle         = "";
            string sPhone            = "";
            string sCellPhone        = "";
            string sAdress           = "";
            string sEmail            = "";

            try
            {
                using (BDRAEntities db = new BDRAEntities())
                {
                    foreach (var data in lsData)
                    {
                        cont += 1;
                        if (cont == 1)
                        {
                            continue;
                        }

                        Console.WriteLine(sline);
                        Console.WriteLine("Validanto linea: " + cont);
                        Console.WriteLine(data);
                        var aData = data.Split(separator);

                        sDocumentByClient = aData[(int)atrContact.clientDocument].ToString();

                        clientByContact = db.Client.Where(cl => cl.cli_document == sDocumentByClient)
                                          .Select(cl => new ClientViewModel {
                            id = cl.cli_document, name = cl.cli_name
                        })
                                          .FirstOrDefault();

                        if (clientByContact != null)
                        {
                            Console.WriteLine("Cliente: " + clientByContact.name);

                            sNameByContact = aData[(int)atrContact.name].ToString();

                            Console.WriteLine("Contacto: " + sNameByContact);

                            var name     = "";
                            var lastName = "";

                            var aName = sNameByContact.Split(" ");

                            for (int i = 0; i < aName.Length; i++)
                            {
                                if (aName.Length == 2)
                                {
                                    if (i == 0)
                                    {
                                        name = aName[i];
                                    }
                                    else
                                    {
                                        lastName = aName[i];
                                    }
                                }
                                else
                                {
                                    if (i <= 1)
                                    {
                                        name += aName[i] + " ";
                                    }
                                    else
                                    {
                                        lastName += aName[i] + " ";
                                    }
                                }
                            }

                            Console.WriteLine("Nombre del contacto: " + name);

                            if (name.Trim() == "")
                            {
                                Console.WriteLine("Contacto no valido .............");
                                continue;
                            }
                            Console.WriteLine("Apellido del contacto: " + lastName);

                            sJobTitle = aData[(int)atrContact.jobTitle].ToString().ToUpper().Trim();
                            sJobTitle = sJobTitle.Replace("  ", " ");


                            Console.WriteLine("Cargo: " + sJobTitle);

                            jobTitle = db.JobTitlesClient.Where(jt => jt.jtcl_description.ToUpper() == sJobTitle)
                                       .Select(jt => new JobTitleViewModel {
                                id = jt.jtcl_id, description = jt.jtcl_description
                            })
                                       .FirstOrDefault();


                            if (jobTitle == null)
                            {
                                JobTitlesClient jt = new JobTitlesClient();
                                jt.jtcl_description = sJobTitle;
                                jt.jtcl_state       = true;

                                db.JobTitlesClient.Add(jt);
                                db.SaveChanges();
                                Console.WriteLine("Se crea cargo en la bd...");


                                jobTitle = db.JobTitlesClient.Where(jt => jt.jtcl_description.ToUpper() == sJobTitle)
                                           .Select(jt => new JobTitleViewModel {
                                    id = jt.jtcl_id, description = jt.jtcl_description
                                })
                                           .FirstOrDefault();
                            }

                            sPhone = aData[(int)atrContact.phone].ToString().Trim();
                            Console.WriteLine("Teléfono: " + sPhone);
                            sCellPhone = aData[(int)atrContact.cellphone].ToString().Trim();
                            Console.WriteLine("Celular: " + sCellPhone);
                            sAdress = aData[(int)atrContact.adress].ToString().Trim();
                            Console.WriteLine("Dirección: " + sAdress);
                            sEmail = aData[(int)atrContact.email].ToString().Trim();
                            Console.WriteLine("Email: " + sEmail);

                            branchByContact = db.branch.Where(b => b.cli_document == clientByContact.id && b.bra_isMain == true)
                                              .Select(b => new BranchViewModel {
                                id = b.bra_id, name = b.bra_name
                            })
                                              .FirstOrDefault();

                            if (branchByContact == null)
                            {
                                branch branchCnt = new branch();
                                branchCnt.bra_isMain   = true;
                                branchCnt.bra_state    = true;
                                branchCnt.bra_name     = "PRINCIPAL " + clientByContact.name;
                                branchCnt.cli_document = clientByContact.id;

                                db.branch.Add(branchCnt);
                                db.SaveChanges();

                                branchByContact = db.branch.Where(b => b.cli_document == clientByContact.id && b.bra_isMain == true)
                                                  .Select(b => new BranchViewModel {
                                    id = b.bra_id, name = b.bra_name
                                })
                                                  .FirstOrDefault();
                            }


                            Console.WriteLine("Sucursal id: " + branchByContact.id + " - " + branchByContact.name);

                            ContactViewModel cnt = new ContactViewModel();
                            cnt.branch    = branchByContact;
                            cnt.name      = name;
                            cnt.lastName  = lastName;
                            cnt.phone     = sPhone;
                            cnt.cellPhone = sCellPhone;
                            cnt.adress    = sAdress;
                            cnt.email     = sEmail;
                            cnt.jobTitle  = jobTitle;

                            lsContacts.Add(cnt);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }



            return(lsContacts);
        }