예제 #1
0
        public bool SaveDistribuidor(Distribuidores distribuidor, ref string resultado, string nombreCompleto,
                                     string iniciales)
        {
            try
            {
                if (Validar(distribuidor))
                {
                    using (var db = new NtLinkLocalServiceEntities())
                    {
                        if (distribuidor.IdDistribuidor == 0)
                        {
                            // Crear random password
                            if (db.aspnet_Membership.Any(p => p.LoweredEmail == distribuidor.Email.ToLower()))
                            {
                                throw new FaultException("El Email ya fue registrado");
                            }
                            db.Distribuidores.AddObject(distribuidor);
                            db.SaveChanges();
                            var password = Membership.GeneratePassword(8, 2);
                            var userName = distribuidor.Email;
                            NtLinkUsuarios.CreateUserDis(userName, password, distribuidor.Email,
                                                         (int)distribuidor.IdDistribuidor, "Administrador",
                                                         nombreCompleto, iniciales);
                            Logger.Info("se creó el usuario: " + userName + " con el password: "******"se creó el usuario: " + userName + " con el password: "******"Registro actualizado correctamente";
                        }


                        return(true);
                    }
                }
                return(false);
            }
            catch (FaultException fe)
            {
                throw;
            }
            catch (Exception ee)
            {
                resultado = "Error al guardar el registro";
                Logger.Error(ee);
                if (ee.InnerException != null)
                {
                    Logger.Error(ee.InnerException);
                }
                return(false);
            }
        }
예제 #2
0
        public bool SaveSistema(Sistemas sistema, ref string resultado, string nombreCompleto, string iniciales)
        {
            try
            {
                if (Validar(sistema))
                {
                    using (var db = new NtLinkLocalServiceEntities())
                    {
                        if (sistema.IdSistema == 0)
                        {
                            // Crear random password
                            if (db.aspnet_Membership.Any(p => p.LoweredEmail == sistema.Email.ToLower()))
                            {
                                throw new FaultException("El Email ya fue registrado");
                            }
                            db.Sistemas.AddObject(sistema);
                            db.SaveChanges();
                            var     password = Membership.GeneratePassword(8, 2);
                            var     userName = sistema.Email;
                            empresa em       = new empresa()
                            {
                                PrimeraVez    = true,
                                RazonSocial   = sistema.RazonSocial,
                                RFC           = sistema.Rfc,
                                Ciudad        = sistema.Ciudad,
                                Colonia       = sistema.Colonia,
                                CP            = sistema.Cp,
                                Direccion     = sistema.Direccion,
                                Email         = sistema.Email,
                                Estado        = sistema.Estado,
                                idSistema     = sistema.IdSistema,
                                RegimenFiscal = sistema.RegimenFiscal,
                                Linea         = "A"
                            };
                            NtLinkEmpresa emp = new NtLinkEmpresa();
                            emp.Save(em, null);
                            var e2 = emp.GetByRfc(em.RFC);
                            NtLinkUsuarios.CreateUser(userName, password, sistema.Email, e2.IdEmpresa, "Administrador", nombreCompleto, iniciales);
                            Logger.Info("se creó el usuario: " + userName + " con el password: "******"se creó el usuario: " + userName + " con el password: "******"Registro actualizado correctamente";
                        }


                        return(true);
                    }
                }
                return(false);
            }
            catch (FaultException fe)
            {
                throw;
            }
            catch (Exception ee)
            {
                resultado = "Error al guardar el registro";
                Logger.Error(ee);
                if (ee.InnerException != null)
                {
                    Logger.Error(ee.InnerException);
                }
                return(false);
            }
        }