public ContentResult AddClick(string name, HttpPostedFileBase file) { string content = null; vatlieu item = new vatlieu(); item.Ten = name; item.SoLuong = 0; item.CreateDate = DateTime.Now; item.UpdateDate = DateTime.Now; if (file != null) { string pic = ConvertToUnSign(name).Replace(" ", "-").ToLower() + System.IO.Path.GetExtension(file.FileName).ToLower(); string path = System.IO.Path.Combine(Server.MapPath("/Assets/Images"), pic); file.SaveAs(path); item.Image = "/Assets/Images/" + pic; System.IO.File.Delete(System.IO.Path.Combine(Server.MapPath("/Assets/Images"), file.FileName)); } var result = new VatLieuDAO().Insert(item); if (result) { content = "<script type='text/javascript'>alert(' Thêm thành công');window.location.href = '/Storage/StockCur/';</script>"; } else { content = "<script type='text/javascript'>alert(' Thêm thất bại');</script>"; } return(Content(content)); }
public bool Insert(vatlieu item) { try { db.vatlieux.Add(item); db.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(vatlieu item) { var dbEntry = db.vatlieux.SingleOrDefault(x => x.ID == item.ID); try { dbEntry.Image = item.Image; dbEntry.Ten = item.Ten; dbEntry.UpdateDate = item.UpdateDate; db.SaveChanges(); return(true); } catch { return(false); } }