示例#1
0
        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));
        }
示例#2
0
 public bool Insert(vatlieu item)
 {
     try
     {
         db.vatlieux.Add(item);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#3
0
        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);
            }
        }