예제 #1
0
        public ActionResult Edit(Product product)
        {
            if (ModelState.IsValid)
            {
                if (product.ImageFile != null)
                {
                    var pic = string.Empty;

                    var folder  = "~/Content/Products";
                    var file    = string.Format("{0}-{1}.jpg", product.ProductId, product.Description);
                    var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file);

                    if (respose)
                    {
                        pic           = string.Format("{0}/{1}", folder, file);
                        product.Image = pic;
                    }
                }

                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelpers.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId);

            return(View(product));
        }
예제 #2
0
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();

                if (company.LogoFile != null)
                {
                    var folder  = "~/Content/Logos";
                    var file    = string.Format("{0}-{1}.jpg", company.CompanyId, company.Name);
                    var respose = FilesHelpers.UploadPhoto(company.LogoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        company.Logo = pic;
                        //actalizamos la dv
                        db.Entry(company).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", company.DepartmentId);
            return(View(company));
        }
예제 #3
0
        public async Task <ActionResult> Edit(ProductView view)
        {
            if (ModelState.IsValid)
            {
                var picture = view.ImagePath;
                var folder  = "~/Content/Products";
                if (view.ImageFile != null)
                {
                    picture = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    picture = $"{folder}/{picture}";
                }

                var product = this.ToProduct(view, picture);
                try
                {
                    db.Entry(product).State = EntityState.Modified;

                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                }

                return(RedirectToAction("Index"));
            }
            return(View(view));
        }
예제 #4
0
        public async Task <ActionResult> Create(ProductView view)
        {
            if (ModelState.IsValid)
            {
                var picture = string.Empty;
                var folder  = "~/Content/Products";
                if (view.ImageFile != null)
                {
                    picture = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    picture = $"{folder}/{picture}";
                }

                var product = this.ToProduct(view, picture);

                try
                {
                    db.Products.Add(product);
                    await db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                }
                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
예제 #5
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();

                UsersHelper.CreateUserASP(user.UserName, "User");

                if (user.PhotoFile != null)
                {
                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                        //actalizamos la dv
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
예제 #6
0
        public ActionResult Create(Product product)
        {
            var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();

                if (product.ImageFile != null)
                {
                    var folder  = "~/Content/Products";
                    var file    = string.Format("{0}-{1}.jpg", product.ProductId, product.Description);
                    var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        product.Image = pic;
                        //actalizamos la dv
                        db.Entry(product).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId);
            ViewBag.TaxId      = new SelectList(CombosHelpers.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId);
            return(View(product));
        }
예제 #7
0
        public ActionResult Create(CategoriaVista categoriavista)
        {
            try
            {
                var pic    = string.Empty;
                var folder = "~/Content/ImagenesCategorias";

                if (categoriavista.fotoFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(categoriavista.fotoFile, folder);
                    pic = $"{folder}/{pic}";
                }
                //almaceno los datos en la variable local
                var categoria = this.ToCategoria(categoriavista, pic);

                // comienza la conexión
                MongoClientSettings settings = MongoClientSettings.FromUrl(
                    new MongoUrl(connectionString)
                    );
                settings.SslSettings =
                    new SslSettings()
                {
                    EnabledSslProtocols = SslProtocols.Tls12
                };
                var mongoClient = new MongoClient(settings);
                //var client = new MongoClient(conec);
                var db = mongoClient.GetDatabase(bdname);
                var collectionSettings = new MongoCollectionSettings {
                    ReadPreference = ReadPreference.Nearest
                };



                // var cliente = new MongoClient(conec);

                //var database = cliente.GetDatabase(bdname);
                var listacategorias = db.GetCollection <Categoria>("Categoria");
                //termina la conexión

                listacategorias.InsertOneAsync(categoria);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #8
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic = string.Empty;

                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                    }
                }


                var db2         = new ECommerceContext();
                var currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                db2.Dispose();

                //actalizamos la dv
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
예제 #9
0
        public ActionResult Create(EntidadVista entidadvista)
        {
            try
            {
                var pic    = string.Empty;
                var folder = "~/Content/ImagenesEntidades";

                if (entidadvista.fotoFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(entidadvista.fotoFile, folder);
                    pic = $"{folder}/{pic}";
                }
                //almaceno los datos en la variable local
                var entidad = this.ToEntidad(entidadvista, pic);


                string connectionString =
                    @"mongodb://*****:*****@appturismo.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@appturismo@";
                MongoClientSettings settings = MongoClientSettings.FromUrl(
                    new MongoUrl(connectionString)
                    );
                settings.SslSettings =
                    new SslSettings()
                {
                    EnabledSslProtocols = SslProtocols.Tls12
                };
                var mongoClient = new MongoClient(settings);
                // var cliente = new MongoClient(conec);
                //bd = cliente.GetDatabase(bdname);
                var database = mongoClient.GetDatabase(bdname);

                var entidades = database.GetCollection <Entidad>("Entidad");
                entidades.InsertOneAsync(entidad);
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #10
0
        public async Task <ActionResult> Create(CategoryView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = string.Empty;
                var folder = "~/Content/Categories";

                if (view.ImageFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    pic = $"{folder}/{pic}";
                }

                var category = this.ToCategory(view, pic);
                this.db.Categories.Add(category);
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
예제 #11
0
        public async Task <ActionResult> Edit(CategoryView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = view.ImagePath;
                var folder = "~/Content/Categories";

                if (view.ImageFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    pic = $"{folder}/{pic}";
                }

                var category = this.ToCategory(view, pic);
                this.db.Entry(category).State = EntityState.Modified;
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
예제 #12
0
        public async Task <ActionResult> Create(ProductView view)
        {
            //valida la notacion
            if (ModelState.IsValid)
            {
                var pic    = string.Empty;
                var folder = "~/Content/Products";

                if (view.ImageFile != null)
                {
                    pic = FilesHelpers.UploadPhoto(view.ImageFile, folder);
                    pic = $"{folder}/{pic}";
                }
                var product = this.ToProduct(view, pic);
                //sube la imagen a la bd
                this.db.Products.Add(product);
                //guarda en la BD
                await this.db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(view));
        }
예제 #13
0
        public ActionResult Create(State state)
        {
            if (ModelState.IsValid)
            {
                db.States.Add(state);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (state.FlagFile != null)
                    {
                        var folder = "~/Content/Flags";

                        var file = string.Format("{0}.jpg",
                                                 state.StateId);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                state.FlagFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            state.Flag = pic;

                            db.Entry(state).State =
                                EntityState.Modified;

                            db.SaveChanges();
                        }
                    }

                    if (state.ShieldFile != null)
                    {
                        var folder1 = "~/Content/Shields";

                        var file1 = string.Format("{0}.jpg",
                                                  state.StateId);

                        var response1 =
                            FilesHelpers.
                            UploadPhoto(
                                state.ShieldFile,
                                folder1, file1);

                        if (response1)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder1,
                                              file1);

                            state.Shield = pic;

                            db.Entry(state).State =
                                EntityState.Modified;

                            db.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            return(View(state));
        }
예제 #14
0
        public ActionResult Edit(Product product)
        {
            var user =
                db.Users.
                Where(us => us.UserName == User.Identity.Name).
                FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Entry(product).State =
                    EntityState.Modified;

                if (product.ImageFile != null)
                {
                    var folder = "~/Content/Products";

                    var pic = string.Empty;

                    var file = string.Format("{0}.jpg", product.ProductID);

                    var response0 =
                        FilesHelpers.
                        UploadPhoto(
                            product.ImageFile,
                            folder,
                            file);

                    if (response0)
                    {
                        pic = string.Format("{0}/{1}", folder, product.ProductID);

                        product.Image = pic;
                    }
                }

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CategoryId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCategories(
                        user.CompanyId),
                    "CategoryId",
                    "Description",
                    product.CategoryId);

            ViewBag.TaxId =
                new SelectList(
                    ComboBoxHelpers.
                    GetTaxes(
                        user.CompanyId),
                    "TaxId",
                    "Description",
                    product.TaxId);

            return(View(product));
        }
예제 #15
0
        public ActionResult Create(City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);

                try
                {
                    db.SaveChanges();

                    if (city.FlagFile != null)
                    {
                        var folder = "~/Content/Cities/FlagsCities";

                        var file = string.Format("{0}.jpg",
                                                 city.CityId);

                        var response =
                            FilesHelpers.
                            UploadPhoto(
                                city.FlagFile,
                                folder, file);

                        if (response)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            city.Flag = pic;

                            db.Entry(city).State =
                                EntityState.Modified;

                            db.SaveChanges();
                        }
                    }
                    if (city.ShieldFile != null)
                    {
                        var folder1 = "~/Content/Cities/ShieldsCities";

                        var file1 = string.Format("{0}.jpg",
                                                  city.CityId);

                        var response1 =
                            FilesHelpers.
                            UploadPhoto(
                                city.ShieldFile,
                                folder1, file1);

                        if (response1)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder1,
                                              file1);

                            city.Shield = pic;

                            db.Entry(city).State =
                                EntityState.Modified;

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    city.StateId);

            return(View(city));
        }
예제 #16
0
        public ActionResult Create(Customer customer)
        {
            var user =
                db.Users.
                Where(us => us.UserName == User.Identity.Name).
                FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (customer.LogoCFile != null)
                    {
                        var folder = "~/Content/Customers";

                        var file = string.Format("{0}.jpg",
                                                 customer.CustomerID);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                customer.LogoCFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            customer.LogoC = pic;

                            db.Entry(customer).State =
                                EntityState.Modified;

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(customer.StateId),
                    "CityId",
                    "NameCity",
                    customer.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    customer.StateId);

            return(View(customer));
        }
예제 #17
0
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    if (company.LogoFile != null)
                    {
                        var folder = "~/Content/Logos";

                        var file = string.Format("{0}.jpg",
                                                 company.CompanyId);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                company.LogoFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            company.Logo = pic;

                            db.Entry(company).State = EntityState.Modified;

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(company.StateId),
                    "CityId",
                    "NameCity",
                    company.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    company.StateId);

            return(View(company));
        }
예제 #18
0
        public ActionResult Edit(Company company)
        {
            if (ModelState.IsValid)
            {
                if (company.LogoFile != null)
                {
                    var folder = "~/Content/Logos";

                    var pic = string.Empty;

                    var file = string.Format("{0}.jpg", company.CompanyId);

                    var response =
                        FilesHelpers.
                        UploadPhoto(
                            company.LogoFile,
                            folder,
                            file);

                    if (response)
                    {
                        pic = string.Format("{0}/{1}", folder, company.CompanyId);

                        company.Logo = pic;
                    }
                }

                db.Entry(company).State =
                    EntityState.Modified;

                try
                {
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

            ViewBag.CityId =
                new SelectList(
                    ComBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    company.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    company.StateId);

            return(View(company));
        }
예제 #19
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);

                var response = DBHelpers.SaveChanges(db);

                if (response.Succeeded)
                {
                    UsersHelpers.
                    CreateUserASP(user.UserName, "User");

                    if (user.PhotoFile != null)
                    {
                        var folder = "~/Content/Photos";

                        var file = string.Format("{0}.jpg",
                                                 user.UserID);

                        var response0 =
                            FilesHelpers.
                            UploadPhoto(
                                user.PhotoFile,
                                folder, file);

                        if (response0)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            user.Photo = pic;

                            db.Entry(user).State =
                                EntityState.Modified;

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError(
                    string.Empty, response.Message);
            }

            ViewBag.CityId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCities(user.StateId),
                    "CityId",
                    "NameCity",
                    user.CityId);

            ViewBag.CompanyId =
                new SelectList(
                    ComboBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany",
                    user.CompanyId);

            ViewBag.StateId =
                new SelectList(
                    ComboBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    user.StateId);

            return(View(user));
        }
예제 #20
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);

                try
                {
                    db.SaveChanges();

                    UsersHelpers.
                    CreateUserASP(user.UserName, "User");

                    if (user.PhotoFile != null)
                    {
                        var folder = "~/Content/Photos";

                        var file = string.Format("{0}.jpg",
                                                 user.UserID);

                        var response =
                            FilesHelpers.
                            UploadPhoto(
                                user.PhotoFile,
                                folder, file);

                        if (response)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            user.Photo = pic;

                            db.Entry(user).State = EntityState.Modified;

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

            ViewBag.CityId =
                new SelectList(
                    ComBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    user.CityId);

            ViewBag.CompanyId =
                new SelectList(
                    ComBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany",
                    user.CompanyId);

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    user.StateId);

            return(View(user));
        }