Esempio n. 1
0
 public ActionResult Edit(Person person)
 {
     if (ModelState.IsValid)
     {
         db.Entry(person).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "Id,PublishedDate,Content,GameId,UserId")] Review review)
 {
     if (ModelState.IsValid)
     {
         db.Entry(review).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.GameId = new SelectList(db.Games, "Id", "Name", review.GameId);
     return(View(review));
 }
Esempio n. 3
0
        public IActionResult Edit(int?id, Adhoc ticket)
        {
            if (id == null)
            {
                return(NotFound());
            }


            string userId = null;

            // When user id is unavailable, display user as "Anomymous"
            if (User.Identity.Name == null || User.Identity.Name == "" || User.Identity.Name == "Anomymous user")
            {
                userId = "Anomymous";
            }
            else
            {
                userId = User.Identity.Name;
            }

            if (ModelState.IsValid)
            {
                // When status is changed by analyst to closed/cancelled, update analyst id (whoever closed the ticket)
                if (ticket.Status == "Closed" || ticket.Status == "Cancelled")
                {
                    Adhoc oticket = new Adhoc {
                        ID = ticket.ID, Status = ticket.Status, SupportAnalyst = userId, Details = ticket.Details, Type = ticket.Type
                    };
                    oticket.CompletedDate = System.DateTime.Now;
                    _contextAdhoc.Entry(oticket).Property("CompletedDate").IsModified  = true;
                    _contextAdhoc.Entry(oticket).Property("Status").IsModified         = true;
                    _contextAdhoc.Entry(oticket).Property("SupportAnalyst").IsModified = true;
                    _contextAdhoc.Entry(oticket).Property("Details").IsModified        = true;
                    _contextAdhoc.Entry(oticket).Property("Type").IsModified           = true;
                }
                else
                {
                    Adhoc oticket = new Adhoc {
                        ID = ticket.ID, Status = ticket.Status, SupportAnalyst = userId, Details = ticket.Details, Type = ticket.Type
                    };
                    _contextAdhoc.Entry(oticket).Property("Status").IsModified         = true;
                    _contextAdhoc.Entry(oticket).Property("SupportAnalyst").IsModified = true;
                    _contextAdhoc.Entry(oticket).Property("Details").IsModified        = true;
                    _contextAdhoc.Entry(oticket).Property("Type").IsModified           = true;
                }

                _contextAdhoc.SaveChanges();

                TempData["message"] = "Person edited!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "There has been errors");
            return(View(ticket));
        }
 /// update data or edit any player
 public JsonResult  UpdatePlayer(Player player)
 {
     _context.Entry(player).State = System.Data.Entity.EntityState.Modified;
     _context.SaveChanges();
     return(Json(new { status = "player updated sucessfully" }
                 ));
 }
Esempio n. 5
0
        public ActionResult Edit(Product product)
        {
            foreach (var category in db.Categories)
            {
                product.CategoryList.Add(new SelectListItem {
                    Text = category.Name, Value = category.Id.ToString()
                });
            }
            if (product.CategoryId > 0)
            {
                product.AttributeList = BindAttributeList(product.CategoryId);
                if (product.AttributeId > 0 && product.AttributeList.Select(c => c.Value).Contains(product.AttributeId.ToString()))
                {
                    product.AttributeValuesList = BindAttributeValueList(product.AttributeId);
                }
            }
            if (ModelState.IsValid)
            {
                if (product.CategoryId > 0 && product.AttributeId > 0 && product.AttributeValuesId > 0)
                {
                    if (product.AttributeValuesList.Select(x => x.Value).Contains(product.AttributeValuesId.ToString()))
                    {
                        db.Entry(product).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
            }

            return(View(product));
        }
        public ActionResult Edit([Bind(Include = "Id,PublishedDate,GameId,UserId")] GameplayCreateEditViewModel model)
        {
            var gameplay = new Gameplay {
                Id = model.Id, GameId = model.GameId, PublishedDate = model.PublishedDate
            };

            foreach (var item in db.Users)
            {
                if (item.UserName == User.Identity.Name)
                {
                    gameplay.UserId = item.Id;
                }
            }

            if (ModelState.IsValid)
            {
                db.Entry(gameplay).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("UserGameplays", "Account"));
            }
            var games          = db.Games.Where(c => c.Accepted == true);
            var gameViewModels = Mapper.Map <IEnumerable <Game>, IEnumerable <GameViewModel> >(games);
            var data           = gameViewModels.ToList().Select(t => new GroupedSelectListItem
            {
                GroupKey  = t.CategoryName.ToString(),
                GroupName = t.CategoryName,
                Text      = t.Name,
                Value     = t.Id.ToString()
            });

            model.Games = data;

            return(View(model));
        }
Esempio n. 7
0
        public IHttpActionResult PutEventMaster(int id, EventMaster eventMaster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventMaster.EventId)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult AddPerson(PersonModel personModel)
 {
     try
     {
         using (CrudContext db = new CrudContext())
         {
             var teacher = new Teacher()
             {
                 Address = new Address()
                 {
                     Street = personModel.Street,
                     City   = new City()
                     {
                         Id = personModel.CityId,
                         // CountryId = 1
                     }
                 },
                 Name  = personModel.Name,
                 Email = personModel.Email
             };
             db.Entry(teacher.Address.City).State = EntityState.Unchanged;
             db.Persons.Add(teacher);
             db.SaveChanges();
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(ex.Message, JsonRequestBehavior.AllowGet));
     }
 }
        public virtual TEntity Atualizar(TEntity obj)
        {
            var entry = Db.Entry(obj);

            DbSet.Attach(obj);
            entry.State = EntityState.Modified;

            return(obj);
        }
Esempio n. 10
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Address")] Person person)
 {
     if (ModelState.IsValid)
     {
         db.Entry(person).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(person));
 }
Esempio n. 11
0
 public ActionResult Edit([Bind(Include = "Id,Name,PostalCode")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(city));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Details")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "EmpleadoId,Nombre,Email,Telefono,Direccion")] Empleado empleado)
 {
     if (ModelState.IsValid)
     {
         db.Entry(empleado).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(empleado));
 }
Esempio n. 14
0
 public ActionResult Edit(Employee employee)
 {
     if (ModelState.IsValid)
     {
         _crudContext.Entry(employee).State = EntityState.Modified;
         _crudContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Esempio n. 15
0
 public ActionResult Edit([Bind(Include = "Id,Name,Category,Price")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Esempio n. 16
0
        public ActionResult Edit(Mascota mascota)
        {
            if (ModelState.IsValid)
            {
                _context.Entry(mascota).State = EntityState.Modified;
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(mascota));
        }
 public ActionResult Edit([Bind(Include = "ID,Name,Brand,Weight,CurrentCategoryId")] Bike bike)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bike).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CurrentCategoryId = new SelectList(db.Categories, "ID", "Name", bike.CurrentCategoryId);
     return(View(bike));
 }
Esempio n. 18
0
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Entry(category).State = EntityState.Modified;
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Esempio n. 19
0
 public ActionResult Edit(AttributeValues attributeValues)
 {
     if (ModelState.IsValid)
     {
         db.Entry(attributeValues).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AttributeId = new SelectList(db.Attributes, "Id", "Name", attributeValues.AttributeId);
     return(View(attributeValues));
 }
Esempio n. 20
0
        public void ExplicitLoadingRead()
        {
            List <Contact> contactList = _db.Contacts.Include(c => c.Person).ToList(); // Load also Person entities

            Writes(contactList.ToArray());
            Writes(contactList.Select(c => c.Person).ToArray());

            Contact contact = _db.Contacts.First();

            _db.Entry(contact).Reference(c => c.Person).Load(); // It will load from the Db o from the Memory
            Writes(contact.Person);
        }
Esempio n. 21
0
        private static void ExplicitLoading()
        {
            using (var context = new CrudContext())
            {

                var projectCategory = context.ProjectCategories.First();
                context.Entry(projectCategory).Collection(pc => pc.Projects).Load();

                Console.WriteLine("project count for {0},{1}", projectCategory.Name, projectCategory.Projects.Count());

            }
        }
Esempio n. 22
0
 public ActionResult Updateusers(UserModel user)
 {
     if (ModelState.IsValid)
     {
         CrudContext db = new CrudContext();
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.Message = user.UserName + " successfully edited.";
         return(RedirectToAction("Retrive"));
     }
     return(View("Retrive"));
 }
Esempio n. 23
0
 public IActionResult Edited(int dishid, Dish thisDish)
 {
     if (ModelState.IsValid)
     {
         thisDish.DishId = dishid;
         dbContext.Update(thisDish);
         dbContext.Entry(thisDish).Property("CreatedAt").IsModified = false;
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("Edit", thisDish));
     }
 }
Esempio n. 24
0
        public IActionResult Edit(int?id, Admins admin)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                Admins oAdmin = new Admins {
                    ID = admin.ID, login = admin.login, name = admin.name, role = admin.role
                };
                _contextAdmin.Entry(oAdmin).Property("login").IsModified = true;
                _contextAdmin.Entry(oAdmin).Property("name").IsModified  = true;
                _contextAdmin.Entry(oAdmin).Property("role").IsModified  = true;

                _contextAdmin.SaveChanges();
                TempData["message"] = "Admin edited!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "There have been errors");
            return(View(admin));
        }
Esempio n. 25
0
        public IActionResult UpdateDish(int DishId, Dishes UpDish)
        {
            if (ModelState.IsValid)
            {
                UpDish.DishId = DishId;
                dbContext.Update(UpDish);

                dbContext.Entry(UpDish).Property("CreatedAt").IsModified = false;
                dbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(EditDish(DishId));
            }
        }
Esempio n. 26
0
        public async Task UpdateAsync(int id, T entity)
        {
            T newEntity = await currentDbSet.Where(entity => entity.Id == entity.Id).FirstOrDefaultAsync();

            if (newEntity is null)
            {
                entity.Id = 0;
                await currentDbSet.AddAsync(entity);
            }
            else
            {
                Context.Entry(currentDbSet.FirstOrDefault(entity => entity.Id == id)).CurrentValues.SetValues(entity);
            }

            await Context.SaveChangesAsync();
        }
Esempio n. 27
0
 public void Update(TEntity entity)
 {
     _dbSet.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
     _context.SaveChanges();
 }
Esempio n. 28
0
 public void Update(TEntity entity)
 {
     _dbSet.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
     Commit();
 }
 public void EditGame(Game game)
 {
     _context.Entry(game).State = EntityState.Modified;
     _context.SaveChanges();
 }
 public void EditUser(User user)
 {
     _context.Entry(user).State = EntityState.Modified;
     _context.SaveChanges();
 }
Esempio n. 31
0
 public JsonResult UpdateProveedor(Proveedor provedor)
 {
     _context.Entry(provedor).State = System.Data.Entity.EntityState.Modified;
     _context.SaveChanges();
     return(Json(new { status = "El Proveedor ha actualizado con exito" }));
 }