Пример #1
0
        public ActionResult Edit(string id, FormCollection collection, RegisterBindingModel reg)
        {
            try
            {
                // TODO: Add update logic here

                ZonaFl.Business.SubSystems.SUser     usern  = new Business.SubSystems.SUser();
                ZonaFl.Business.SubSystems.SCategory usersk = new Business.SubSystems.SCategory();
                ZonaFl.Business.SubSystems.SSkill    sskill = new Business.SubSystems.SSkill();
                RegisterBindingModel user = reg;
                if (user.Empresa == null)
                {
                    user.Empresa = false;
                }

                if (user.Freelance == null)
                {
                    user.Freelance = false;
                }

                RegisterBindingModel rmb = new RegisterBindingModel();
                rmb.Skills = user.Skills;
                List <Persistence.Entities.Skill> skills = rmb.Skills.Select(e => new Persistence.Entities.Skill().InjectFrom(e)).Cast <Persistence.Entities.Skill>().ToList();
                AspNetUsers aspuser = new AspNetUsers();
                var         useru   = UserManager.FindByEmail(user.Email);
                for (int i = 0; i < skills.Count(); i++)
                {
                    ZonaFl.Persistence.Entities.Category category = null;
                    var      skill            = sskill.FindSkillByName(user.Skills[i].Name);
                    string[] stringSeparators = new string[] { "\n" };
                    string   result           = user.Skills[i].CategorySkill.Split(stringSeparators, StringSplitOptions.None)[0];

                    category = usersk.FindCategoryByName(result);

                    if (category == null)
                    {
                        try
                        {
                            category = usersk.InsertCategory(result);
                        }
                        catch (Exception er)
                        {
                            return(Json(new { success = false, issue = user, errors = er.Message, tipo = user, UserEmail = useru.Email }));
                        }
                    }

                    skills[i].IdHtml     = user.Skills[i].IdHtml;
                    skills[i].Category   = category;
                    skills[i].CategoryId = category.Id;
                }

                useru.City            = user.City;
                useru.Country         = user.Country;
                useru.UserName        = user.UserName;
                useru.DescUser        = user.DescUser;
                useru.PhoneNumber     = user.PhoneNumber.ToString();
                useru.FirstMiddleName = user.FirstMiddleName;
                useru.Image           = user.Image;

                aspuser.InjectFrom(useru);

                try
                {
                    skills = usern.InsertSkillsByUser(skills, aspuser);
                }
                catch (Exception er)
                {
                    return(Json(new { success = false, issue = user, errors = er.Message, tipo = aspuser, UserEmail = useru.Email }));
                }

                try
                {
                    IdentityResult result = UserManager.Update(useru);

                    if (!result.Succeeded)
                    {
                        return(View("Error"));
                    }
                }
                catch (Exception er)
                {
                    return(View("Error"));
                    //return Json(new { success = false, issue = user, errors = er.Message, tipo = user, UserEmail = useru.Email });
                    //return InternalServerError(er);
                }

                return(RedirectToAction("EditById", new { id = id }));
                //return Json(new { success = true, issue = user, errors = "", tipo = aspuser, UserEmail = useru.Email });
                //return Ok();
            }
            catch
            {
                return(View("Error"));
            }
        }
Пример #2
0
        public async Task <IHttpActionResult> InsertSkills(List <RegisterBindingModel> userl)
        {
            //if (!ModelState.IsValid)
            //{
            //string messages = string.Join("; ", ModelState.Values
            //                        .SelectMany(x => x.Errors)
            //                        .Select(x => x.ErrorMessage));


            //return Json(new { success = false, issue = "", errors = messages });


            //}
            ZonaFl.Business.SubSystems.SUser     usern  = new Business.SubSystems.SUser();
            ZonaFl.Business.SubSystems.SCategory usersk = new Business.SubSystems.SCategory();
            ZonaFl.Business.SubSystems.SSkill    sskill = new Business.SubSystems.SSkill();
            RegisterBindingModel user = userl[0];

            if (user.Empresa == null)
            {
                user.Empresa = false;
            }

            if (user.Freelance == null)
            {
                user.Freelance = false;
            }

            RegisterBindingModel rmb = new RegisterBindingModel();

            rmb.Skills  = user.Skills;
            rmb.Company = user.Company;
            Persistence.Entities.Company company = new Persistence.Entities.Company();
            if (user.Company != null)
            {
                company.InjectFrom(user.Company.FirstOrDefault());
            }
            List <Persistence.Entities.Skill> skills = rmb.Skills.Select(e => new Persistence.Entities.Skill().InjectFrom(e)).Cast <Persistence.Entities.Skill>().ToList();
            AspNetUsers aspuser = new AspNetUsers();

            var useru = UserManager.FindByEmail(user.Email);


            for (int i = 0; i < skills.Count(); i++)
            {
                ZonaFl.Persistence.Entities.Category category = null;
                var      skill            = sskill.FindSkillByName(user.Skills[i].Name);
                string[] stringSeparators = new string[] { "\n" };
                string   result           = user.Skills[i].CategorySkill.Split(stringSeparators, StringSplitOptions.None)[0];

                category = usersk.FindCategoryByName(result);

                if (category == null)
                {
                    try
                    {
                        category = usersk.InsertCategory(result);
                    }
                    catch (Exception er)
                    {
                        return(Json(new { success = false, issue = user, errors = er.Message, tipo = user, UserEmail = useru.Email }));
                    }
                }

                skills[i].IdHtml     = user.Skills[i].IdHtml;
                skills[i].Category   = category;
                skills[i].CategoryId = category.Id;
            }

            useru.City            = user.City;
            useru.Country         = user.Country;
            useru.UserName        = user.UserName;
            useru.DescUser        = user.DescUser;
            useru.PhoneNumber     = user.PhoneNumber.ToString();
            useru.FirstMiddleName = user.FirstMiddleName;
            useru.Image           = user.Image;
            useru.Empresa         = user.Empresa;

            aspuser.InjectFrom(useru);
            aspuser.NoTrabajadores = user.NumeroEmp;

            try
            {
                Business.Log4NetLogger logger2 = new Business.Log4NetLogger();
                if (!useru.Empresa)
                {
                    if (skills.Count > 0)
                    {
                        skills = usern.InsertSkillsByUser(skills, aspuser);
                        logger2.Info("Inserción Usuario Categoria:" + useru.Id + "," + "UsuarioCategoria:" + skills.FirstOrDefault().CategoryId + ",Email:" + aspuser.Email);
                    }
                }
            }
            catch (Exception er)
            {
                return(Json(new { success = false, issue = user, errors = er.Message, tipo = aspuser, UserEmail = useru.Email }));
            }

            try
            {
                SUser suser = new SUser();
                aspuser.Empresa   = useru.Empresa;
                aspuser.Freelance = useru.Freelance;
                IdentityResult result = await UserManager.UpdateAsync(useru);

                var userupdate = suser.UpdateUser(aspuser);
                if (useru.Empresa)
                {
                    company.IdUser      = useru.Id;
                    company.Name        = userl[0].Company.Last().Name;
                    company.Mail        = userl[0].Company.Last().Mail;
                    company.Site        = user.UrlEmpresa;
                    company.Sector      = userl[0].Company.Last().Sector;
                    company.RazonSocial = userl[0].Company.Last().RazonSocial;
                    company.Telefono    = userl[0].Company.Last().Telefono;
                    company.Nit         = userl[0].Company.Last().Nit;
                    company.NumeroEmp   = aspuser.NoTrabajadores == null ? 0 : (int)aspuser.NoTrabajadores;
                    company.Description = userl[0].Company.Last().Description;

                    Persistence.Entities.Company companyp = usern.InsertCompany(company);
                }

                if (!result.Succeeded)
                {
                    return(GetErrorResult(result));
                }
            }
            catch (Exception er)
            {
                return(Json(new { success = false, issue = user, errors = er.Message, tipo = user, UserEmail = useru.Email }));
                //return InternalServerError(er);
            }
            aspuser.Empresa   = useru.Empresa;
            aspuser.Freelance = useru.Freelance;
            aspuser.Id        = useru.Id;
            return(Json(new { success = true, issue = user, errors = "", tipo = aspuser, UserEmail = useru.Email }));
            //return Ok();
        }