Пример #1
0
        public ActionResult UserProfile(ProfileEditViewModel model)
        {
            bool error      = false;
            var  identity   = (System.Web.HttpContext.Current.User as MyIdentity.MyPrincipal).Identity as MyIdentity;
            User loggedUser = db.User.FirstOrDefault(a => a.IdCard.Equals(identity.User.IdCard));

            error = (model.profileData.IdCard != identity.User.IdCard) ? !ValidateIdCard(model.profileData.IdCard) : error;
            error = (model.profileData.Username != identity.User.Username && !error) ? !ValidateUserName(model.profileData.Username) : error;

            if (!error && ModelState.IsValid)
            {
                loggedUser.Username        = model.profileData.Username;
                loggedUser.FirstName       = model.profileData.FirstName;
                loggedUser.MiddleName      = model.profileData.MiddleName;
                loggedUser.LastName        = model.profileData.LastName;
                loggedUser.SecondLastName  = model.profileData.SecondLastName;
                loggedUser.IdCard          = model.profileData.IdCard;
                loggedUser.BirthDate       = model.profileData.BirthDate;
                loggedUser.Gender          = model.profileData.Gender;
                loggedUser.Nationality     = model.profileData.Nationality;
                db.Entry(loggedUser).State = EntityState.Modified;
                db.SaveChanges();
                TempData["Success"] = "Profile correctly updated.";
                return(RedirectToAction("UserProfile", "Account"));
            }
            ViewBag.Nationality = new SelectList(db.Country, "IdCountry", "Name", loggedUser.Nationality);
            return(View(model));
        }
        public ActionResult Edit(RegisterRestaurantModel model, HttpPostedFileBase image)
        {
            Restaurant dbRest = db.Restaurant.Find(Session["RestId"]);

            if (ModelState.IsValid)
            {
                if (model.restTypesId != null && model.restTypesId.Any())
                {
                    String typeList = "";
                    foreach (var typeId in model.restTypesId)
                    {
                        typeList += typeId + ",";
                    }
                    db.PR_UpdateRestaurantTypes(model.restaurant.IdRestaurant, typeList.Remove(typeList.Length - 1));
                }
                else
                {
                    db.PR_DeleteRestaurantTypes(model.restaurant.IdRestaurant);
                }

                if (image != null && image.ContentLength > 0)
                {
                    byte[] dbImage = FileUpload(image);
                    dbRest.Logo = dbImage;
                }
                dbRest.Name            = model.restaurant.Name;
                db.Entry(dbRest).State = EntityState.Modified;
                db.SaveChanges();
                TempData["Success"] = dbRest.Name + " edited successfully.";
                return(RedirectToAction("Index"));
            }
            model.selectedItems = new MultiSelectList(db.Type, "IdType", "Name", dbRest.Type.Select(t => t.IdType));
            return(View(model));
        }
Пример #3
0
 public ActionResult Cancel(int?id)
 {
     try
     {
         Check cancelCheck = db.Check.Find(id);
         cancelCheck.Balance         = 0;
         cancelCheck.State           = "Canceled";
         db.Entry(cancelCheck).State = EntityState.Modified;
         db.SaveChanges();
         TempData["Success"] = "Correct.";
     }
     catch (Exception e)
     {
         TempData["Error"] = "There was an error canceling the check.";
         ModelState.AddModelError("", "");
     }
     return(RedirectToAction("Index", "Checks"));
 }
Пример #4
0
 public ActionResult Edit([Bind(Include = "IdType,Name")] Models.Type type)
 {
     if (ModelState.IsValid)
     {
         db.Entry(type).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(type));
 }
Пример #5
0
        public ActionResult UserProfile(ProfileEditViewModel model)
        {
            bool     error      = false;
            var      identity   = (System.Web.HttpContext.Current.User as MyIdentity.MyPrincipal).Identity as MyIdentity;
            User     loggedUser = db.User.FirstOrDefault(a => a.IdCard.Equals(identity.User.IdCard));
            Customer customer   = db.Customer.Find(identity.User.IdCard);

            model.Activity = "";
            model.Change   = "";
            model.Settings = "active";
            error          = (model.profileData.AccountNumber != customer.AccountNumber) ? !ValidateAccountNumber(model.profileData.AccountNumber) : error;
            error          = (model.profileData.IdCard != identity.User.IdCard) ? !ValidateIdCard(model.profileData.IdCard) : error;
            error          = (model.profileData.Username != identity.User.Username && !error) ? !ValidateUserName(model.profileData.Username) : error;
            model.Timeline = db.Review.Where(r => r.IdCustomer == identity.User.IdCard).OrderByDescending(review => review.Date).ToList();

            if (!error && ModelState.IsValid)
            {
                loggedUser.Username        = model.profileData.Username;
                loggedUser.FirstName       = model.profileData.FirstName;
                loggedUser.MiddleName      = model.profileData.MiddleName;
                loggedUser.LastName        = model.profileData.LastName;
                loggedUser.SecondLastName  = model.profileData.SecondLastName;
                loggedUser.IdCard          = model.profileData.IdCard;
                loggedUser.BirthDate       = model.profileData.BirthDate;
                loggedUser.Gender          = model.profileData.Gender;
                loggedUser.Nationality     = model.profileData.Nationality;
                db.Entry(loggedUser).State = EntityState.Modified;

                customer.AccountNumber   = model.profileData.AccountNumber;
                db.Entry(customer).State = EntityState.Modified;
                db.SaveChanges();
                TempData["Success"] = "Profile correctly updated.";

                return(View(model));
            }

            ViewBag.Nationality = new SelectList(db.Country, "IdCountry", "Name", loggedUser.Nationality);
            return(View(model));
        }
Пример #6
0
        public ActionResult Edit(DishRegister model)
        {
            if (!ModelState.IsValid)
            {
                model.selectedItems    = new MultiSelectList(db.Type, "IdType", "Name", model.dish.Type.Select(t => t.IdType));
                model.restaurant       = db.Restaurant.Find(model.idRestaurant);
                model.photos           = db.Photo.ToList().Where(m => m.Dish.Any(n => n.IdDish == model.dish.IdDish));
                model.deletedFilesIds  = "";
                model.uploadFilesNames = "";
                return(View(model));
            }
            if (model.restTypesId != null && model.restTypesId.Any())
            {
                String typeList = "";
                foreach (var typeId in model.restTypesId)
                {
                    typeList += typeId + ",";
                }
                db.PR_UpdateDishTypes(model.dish.IdDish, typeList.Remove(typeList.Length - 1));
            }
            else
            {
                db.PR_DeleteDishTypes(model.dish.IdDish);
            }

            Dish dish = db.Dish.Find(model.dish.IdDish);

            dish.Name            = model.dish.Name;
            dish.Description     = model.dish.Description;
            dish.Price           = model.dish.Price;
            db.Entry(dish).State = EntityState.Modified;

            if (model.deletedFilesIds != null)
            {
                foreach (var idPhotoDelete in model.deletedFilesIds.Split(','))
                {
                    db.PR_DeleteDishPhoto(dish.IdDish, int.Parse(idPhotoDelete));
                }
            }

            if (model.uploadFilesNames != null)
            {
                string[] uploadFiles = model.uploadFilesNames.Split(',');
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFileBase tmpFile = Request.Files[i];
                    if (tmpFile != null && uploadFiles.Any(name => name == tmpFile.FileName) &&
                        uploadFiles.Length > 0)
                    {
                        byte[] dbImage  = FileUpload(tmpFile);
                        Photo  tmpPhoto = new Photo();
                        tmpPhoto.Photo1 = dbImage;
                        db.Photo.Add(tmpPhoto);

                        dish.Photo.Add(tmpPhoto);
                        tmpPhoto.Dish.Add(dish);
                        uploadFiles = uploadFiles.Where(name => name != tmpFile.FileName).ToArray();
                    }
                }
            }

            db.SaveChanges();
            TempData["Success"] = dish.Name + " edited successfully.";
            return(RedirectToAction("Index", "Locals", new { id = dish.IdRestaurant }));
        }
Пример #7
0
        public ActionResult Edit(localRegister dataModel)
        {
            if (!ModelState.IsValid || dataModel.local.IdDistrict == 0)
            {
                if (dataModel.local.IdDistrict == 0)
                {
                    TempData["Error"] = "Please select a District.";
                }
                ViewBag.IdDistrict   = new SelectList(db.District, "IdDistrict", "Name");
                ViewBag.IdRestaurant = new SelectList(db.Restaurant, "IdRestaurant", "Name");
                localRegister model = new localRegister
                {
                    restaurant       = db.Restaurant.Find(dataModel.idRestaurant),
                    cantMesas        = db.Table.Count(cantTable => cantTable.IdLocal == dataModel.local.IdLocal),
                    idRestaurant     = dataModel.idRestaurant,
                    menu             = GetMenuLocalEdit(dataModel.idRestaurant),
                    local            = dataModel.local,
                    photos           = db.Photo.ToList().Where(m => m.Local.Any(n => n.IdLocal == dataModel.local.IdLocal)),
                    uploadFilesNames = "",
                    deletedFilesIds  = ""
                };
                return(View(model));
            }

            using (var dbTran = db.Database.BeginTransaction())
            {
                try
                {
                    Local local = db.Local.Find(dataModel.local.IdLocal);
                    local.Longitude       = dataModel.local.Longitude;
                    local.Latitude        = dataModel.local.Latitude;
                    local.IdDistrict      = dataModel.local.IdDistrict;
                    local.Detail          = dataModel.local.Detail;
                    db.Entry(local).State = EntityState.Modified;

                    if (dataModel.menu != null)
                    {
                        foreach (DishLocal localDish in dataModel.menu)
                        {
                            DishesPerLocal tmpDishesPerLocal = db.DishesPerLocal.Find(local.IdLocal, localDish.idDish);
                            tmpDishesPerLocal.State           = localDish.state;
                            db.Entry(tmpDishesPerLocal).State = EntityState.Modified;
                        }
                    }

                    int cantMesas = db.Table.Count(cantTable => cantTable.IdLocal == local.IdLocal);
                    if (dataModel.cantMesas > cantMesas)
                    {
                        for (int i = cantMesas + 1; i < dataModel.cantMesas; i++)
                        {
                            Table tmpTable = new Table();
                            tmpTable.IdLocal         = local.IdLocal;
                            tmpTable.DistinctiveName = i.ToString();
                            db.Table.Add(tmpTable);
                        }
                    }
                    else if (dataModel.cantMesas < cantMesas)
                    {
                        var tables = db.Table.Where(cantTable => cantTable.IdLocal == local.IdLocal).ToArray();
                        for (int i = cantMesas - 1; i > dataModel.cantMesas; i--)
                        {
                            db.Table.Remove(tables[i]);
                        }
                    }

                    if (dataModel.deletedFilesIds != null)
                    {
                        foreach (var idPhotoDelete in dataModel.deletedFilesIds.Split(','))
                        {
                            db.PR_DeleteLocalPhoto(local.IdLocal, int.Parse(idPhotoDelete));
                        }
                    }

                    if (dataModel.uploadFilesNames != null)
                    {
                        string[] uploadFiles = dataModel.uploadFilesNames.Split(',');
                        for (int i = 0; i < Request.Files.Count; i++)
                        {
                            HttpPostedFileBase tmpFile = Request.Files[i];
                            if (tmpFile != null && uploadFiles.Any(name => name == tmpFile.FileName) && uploadFiles.Length > 0)
                            {
                                byte[] dbImage  = FileUpload(tmpFile);
                                Photo  tmpPhoto = new Photo();
                                tmpPhoto.Photo1 = dbImage;
                                db.Photo.Add(tmpPhoto);

                                local.Photo.Add(tmpPhoto);
                                tmpPhoto.Local.Add(local);
                                uploadFiles = uploadFiles.Where(name => name != tmpFile.FileName).ToArray();
                            }
                        }
                    }

                    db.SaveChanges();
                    dbTran.Commit();
                    TempData["Success"] = "Local edited successfully.";
                    return(RedirectToAction("Index", "Locals", new { id = dataModel.idRestaurant }));
                }
                catch (Exception ex)
                {
                    dbTran.Rollback();
                    TempData["Error"] = ex.ToString();
                    return(RedirectToAction("Edit", "Locals", new { id = dataModel.local.IdLocal }));
                }
            }
        }