Example #1
0
        // Agregar un nuevo usuario al sitio web - Adds a new user to the website.

        public void AddUser(User modelo, bool isAdmin = false, string path = null)
        {
            TextInfo cultInfo = new CultureInfo("en-US", false).TextInfo;

            var usuario    = char.ToUpper(modelo.username.First()) + modelo.username.Substring(1).ToLower().Trim();
            var contraseña = df.GenerateString(12);
            var nombres    = cultInfo.ToTitleCase(modelo.firstnames).Trim();
            var apellidos  = cultInfo.ToTitleCase(modelo.lastnames).Trim();
            var direccion  = df.AddressCorrector(modelo.address).Trim();
            var correo     = modelo.email.ToLower().Trim();
            var edad       = modelo.age;
            var telefono   = modelo.number.Trim();

            using (var context = new DataContext())
            {
                var empleado = new User
                {
                    username    = usuario,
                    password    = sec.EncryptPassword(contraseña),
                    firstnames  = nombres,
                    lastnames   = apellidos,
                    address     = direccion,
                    age         = edad,
                    email       = correo,
                    number      = telefono,
                    admin       = isAdmin,
                    picturePath = path,
                    optPassword = null,
                };

                context.Usuarios.Add(empleado);
                context.SaveChanges();
            }
            email.SendPasswordEmail(correo, usuario, contraseña);
        }
Example #2
0
        public JsonResult ProductValidations(string productName)
        {
            bool   found   = false;
            string product = df.AddressCorrector(productName);
            string json    = "";

            using (var context = new DataContext())
            {
                var search = (from s in context.Productos where s.name == product select s.name).FirstOrDefault();

                if (search == null)
                {
                    found = false;
                }
                if (search != null)
                {
                    found = true;
                }
                var prices = (from s in context.appSettings select new { minimo = s.precioMinimo, maximo = s.precioMaximo }).FirstOrDefault();
                if (prices == null)
                {
                    json = JsonConvert.SerializeObject(new { name = found, minimo = "", maximo = "" });
                }
                if (prices != null)
                {
                    json = JsonConvert.SerializeObject(new { name = found, prices.minimo, prices.maximo });
                }

                return(Json(json, JsonRequestBehavior.AllowGet));
            }
        }
Example #3
0
        public void AddProduct(Product modelo, string imgPath1, string imgPath2 = null,
                               string imgPath3 = null, string imgPath4 = null)
        {
            string productName  = df.AddressCorrector(modelo.name);
            string pDescription = df.FirstLetterToUpper(modelo.description);

            using (var context = new DataContext())
            {
                var producto = new Product
                {
                    name            = productName.Trim(),
                    description     = pDescription.Trim(),
                    price           = Math.Round(modelo.price, 2, MidpointRounding.ToEven),
                    mainImage       = imgPath1,
                    secondaryImageA = imgPath2,
                    secondaryImageB = imgPath3,
                    secondaryImageC = imgPath4
                };
                context.Productos.Add(producto);
                context.SaveChanges();
            }
        }
Example #4
0
        public bool GetCustomer(string customer, string employee)
        {
            bool   found        = false;
            string customerName = df.AddressCorrector(customer);
            string employeeName = df.FirstLetterToUpper(employee);

            using (var context = new DataContext())
            {
                var employeeID = (from s in context.Usuarios where s.username == employeeName select s.ID).SingleOrDefault();
                var search     = (from s in context.Clientes where s.razonsocial == customerName && s.employeeID == employeeID
                                  select s.razonsocial).SingleOrDefault();

                if (search != null)
                {
                    found = true;
                }
                else
                {
                    found = false;
                }
            }
            return(found);
        }