public ActionResult Edit([Bind(Include = "Id,Name,Description")] Inventory inventory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(inventory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(inventory));
 }
Esempio n. 2
0
        public ActionResult Edit([Bind(Include = "Id,CategoryId,Name,Variety,PrevItemImage")] Item item, HttpPostedFileBase ItemImage)
        {
            if (ModelState.IsValid)
            {
                item.Category = db.Categories.Find(item.CategoryId);

                // Save Image from file input
                if (ItemImage != null)
                {
                    // delete previous image for current item
                    if (item.PrevItemImage != null && item.PrevItemImage != "")
                    {
                        if (System.IO.File.Exists(HttpContext.Server.MapPath("~/Images/") + item.PrevItemImage))
                        {
                            System.IO.File.Delete(HttpContext.Server.MapPath("~/Images/") + item.PrevItemImage);
                        }
                    }

                    string newFileName = Helpers.Helper.RandomString() + ".jpg";
                    ItemImage.SaveAs(HttpContext.Server.MapPath("~/Images/") + newFileName);
                    item.ItemImage = newFileName;
                }

                db.Entry(item).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Esempio n. 3
0
        public static int UpdateEntryByProperty <T>(this MyDataContext _db, T entity, string EntityKey) where T : class
        {
            DbSet <T> dbSet = _db.Set <T>();

            dbSet.Attach(entity);
            MemberInfo[]             members    = entity.GetType().GetMembers();
            IEnumerable <MemberInfo> properties = members.Where(m => m.MemberType == MemberTypes.Property && m.Name != EntityKey);

            foreach (MemberInfo mInfo in properties)
            {
                object o = entity.GetType().InvokeMember(mInfo.Name, BindingFlags.GetProperty, null, entity, null);
                if (o != null)
                {
                    if (o.GetType().IsPrimitive || o.GetType().IsPublic)
                    {
                        try
                        {
                            DbEntityEntry entry = _db.Entry <T>(entity);
                            entry.Property(mInfo.Name).IsModified = true;
                        }
                        catch
                        {
                        }
                    }
                }
            }

            return(_db.SaveChanges());
        }
Esempio n. 4
0
        // PUT api/MyData/5
        public IHttpActionResult PutMyData(int id, MyData mydata)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mydata.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Vendor vendor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vendor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vendor));
 }
Esempio n. 6
0
 public ActionResult Edit([Bind(Include = "Id,Enum1,Enum2,FlagsEnum")] MyData mydata)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mydata).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(mydata));
 }
Esempio n. 7
0
        public static int UpdateProjectByProperty <T>(this MyDataContext _db, T entity, string EntityKey) where T : class
        {
            DbSet <T> dbSet = _db.Set <T>();

            dbSet.Attach(entity);
            MemberInfo[]             members    = entity.GetType().GetMembers();
            IEnumerable <MemberInfo> properties = members.Where(m => m.MemberType == MemberTypes.Property && m.Name != EntityKey);

            foreach (MemberInfo mInfo in properties)
            {
                object o = entity.GetType().InvokeMember(mInfo.Name, BindingFlags.GetProperty, null, entity, null);
                if (o != null)
                {
                    if (o.GetType().IsPrimitive || o.GetType().IsPublic)
                    {
                        try
                        {
                            DbEntityEntry entry = _db.Entry <T>(entity);
                            entry.Property(mInfo.Name).IsModified = true;
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    if (mInfo.Name.ToLower() == "opening_time" || mInfo.Name.ToLower() == "checkin_time" || mInfo.Name.ToLower() == "report_effective_hours" || mInfo.Name.ToLower() == "takelook_effective_days" || mInfo.Name.ToLower() == "remarks_kind" || mInfo.Name.ToLower() == "partner_begin_time" || mInfo.Name.ToLower() == "partner_end_time" || mInfo.Name.ToLower() == "takelook_add_num" || mInfo.Name.ToLower() == "dading_add_num")
                    {
                        try
                        {
                            DbEntityEntry entry = _db.Entry <T>(entity);
                            entry.Property(mInfo.Name).IsModified = true;
                        }
                        catch
                        {
                        }
                    }
                }
            }

            return(_db.SaveChanges());
        }
 public ActionResult Edit([Bind(Include = "Admin_Id,Password")] Admin admin)
 {
     if (ModelState.IsValid)
     {
         db.Entry(admin).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(admin);
 }
 public ActionResult Edit([Bind(Include = "Dept_Id,Name")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(department));
 }
Esempio n. 10
0
 public void Get(User newUser)
 {
     using (var db = new MyDataContext())
     {
         db.Entry(newUser).State = newUser.UserId == 0 ?
                                   System.Data.Entity.EntityState.Added :
                                   System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 11
0
 public void Post(Comment comment)
 {
     using (var db = new MyDataContext())
     {
         db.Entry(comment).State = comment.CommentId == 0 ?
                                   System.Data.Entity.EntityState.Added :
                                   System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 12
0
 public ActionResult Edit([Bind(Include = "Id,Email,Password")] Login login)
 {
     if (ModelState.IsValid)
     {
         db.Entry(login).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(login));
 }
 public ActionResult Edit([Bind(Include = "Stud_Id,Name,Password,Dept_Id,Attendance,TotalDays")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Dept_Id = new SelectList(db.Departments, "Dept_Id", "Name", student.Dept_Id);
     return(View(student));
 }
Esempio n. 14
0
        public ActionResult Index(Persona p)
        {
            if (ModelState.IsValid)
            {
                var persona = GetPersona(p.Nombre, p.Apellido);

                if (p.Id == 0)
                {
                    ViewBag.Crud = "Registrar";

                    if (persona != null)
                    {
                        ViewBag.Message = "Ya hay una Persona con los mismos datos";
                    }
                    else
                    {
                        db.Persona.Add(p);
                        ViewBag.Message = "Se Registró Persona";
                    }
                }
                else
                {
                    ViewBag.Crud = "Modificar";

                    if (persona != null)
                    {
                        ViewBag.Message = "Ya hay una Persona con los mismos datos";
                    }
                    else
                    {
                        db.Entry(p).State = EntityState.Modified;
                        ViewBag.Message   = "Se Grabaron los cambios";
                    }
                }
                db.SaveChanges();
                ViewBag.Listado = db.Persona.ToList();
                return(View("Index", p));
            }
            else
            {
                if (p.Id == 0)
                {
                    ViewBag.Crud = "Registrar";
                }
                else
                {
                    ViewBag.Crud = "Modificar";
                }

                ViewBag.Message = "Aún no ha terminado de llenar los campos";
                ViewBag.Listado = db.Persona.ToList();
                return(View("Index", p));
            }
        }
 public ActionResult Edit([Bind(Include = "Fact_Id,Name,Password,Dept_Id")] Faculty faculty)
 {
     if (ModelState.IsValid)
     {
         db.Entry(faculty).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Dept_Id = new SelectList(db.Departments, "Dept_Id", "Name", faculty.Dept_Id);
     return(View(faculty));
 }
Esempio n. 16
0
        public void Delete(int commentId)
        {
            using (var db = new MyDataContext())
            {
                var commentToDelete = db.Comments.Find(commentId);

                if (commentToDelete != null)
                {
                    db.Entry(commentToDelete).State = System.Data.Entity.EntityState.Deleted;
                }

                db.SaveChanges();
            }
        }
    public virtual TObject Update(TObject data, int id)
    {
        if (data == null)
        {
            return(null);
        }
        TObject obj = Context.Set <TObject>().Find(id);

        if (obj != null)
        {
            Context.Entry(obj).CurrentValues.SetValues(data);
            Context.SaveChanges();
        }
        return(obj);
    }
Esempio n. 18
0
 public void Post(Event @event)
 {
     //Add logic to guard against titles being too long
     //if(@event.Title.Length > 22)
     //{
     //    throw new InvalidOperationException("Bad title length");
     //}
     using (var db = new MyDataContext())
     {
         db.Entry(@event).State = @event.EventId == 0 ?
                                  System.Data.Entity.EntityState.Added :
                                  System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 19
0
        public ActionResult Edit([Bind(Include = "Id,ItemId,VendorId")] VendorSupplyItem item)
        {
            if (ModelState.IsValid)
            {
                item.Item   = db.Items.Find(item.ItemId);
                item.Vendor = db.Vendors.Find(item.VendorId);

                if (IsExistItemVendor(item.ItemId, item.VendorId, item.Id))
                {
                    ModelState.AddModelError("ItemId", "Already exist for Item and Vendor!");

                    ViewBag.Items = new SelectList(db.Items.ToList().Select(
                                                       x => new SelectListItem()
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }
                                                       ), "Value", "Text");

                    ViewBag.Vendors = new SelectList(db.Vendors.ToList().Select(
                                                         x => new SelectListItem()
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }
                                                         ), "Value", "Text");

                    return(View(item));
                }

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