예제 #1
0
        public object UpdateFile([FromBody] SupplierFile obj)
        {
            var msg = new JMessage();

            try
            {
                obj.UpdatedTime = DateTime.Now.Date;
                _context.SupplierFiles.Update(obj);
                _context.SaveChanges();

                msg.Error = false;
                msg.Title = "Đã lưu thay đổi";

                return(msg);
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = "Có lỗi xảy ra!";
                return(msg);
            }
        }
예제 #2
0
        public ActionResult Create(Supplier supplier)
        {
            try
            {
                if (supplier.UploadFiles != null && supplier.UploadFiles[0] != null)
                {
                    var supplierFiles = new List <SupplierFile>();
                    foreach (var uploadFile in supplier.UploadFiles)
                    {
                        var supplierFile = new SupplierFile();
                        var fileByte     = new byte[uploadFile.ContentLength];
                        uploadFile.InputStream.Read(fileByte, 0, uploadFile.ContentLength);
                        supplierFile.File     = fileByte;
                        supplierFile.FileName = uploadFile.FileName;

                        supplierFiles.Add(supplierFile);
                    }

                    supplier.SupplierFiles = supplierFiles;
                }
                var isSaved = _supplierManager.Save(supplier);

                if (isSaved)
                {
                    ViewBag.SMsg = "Saved Successful";
                }
                else
                {
                    ViewBag.FMsg = "Save Failed";
                }
            }
            catch (Exception e)
            {
                ViewBag.FMsg = e.Message;
            }

            return(View());
        }
예제 #3
0
        public object InsertFile([FromBody] SupplierFile obj)
        {
            var msg = new JMessage();

            try
            {
                obj.FileType    = System.IO.Path.GetExtension(obj.FileName);
                obj.CreatedBy   = ESEIM.AppContext.UserName;
                obj.CreatedTime = DateTime.Now.Date;
                _context.SupplierFiles.Add(obj);
                _context.SaveChanges();
                msg.Error = false;
                msg.Title = "Thêm thành công";
                return(Json(msg));
            }
            catch (Exception ex)
            {
                msg.Error  = true;
                msg.Title  = "Có lỗi xảy ra!";
                msg.Object = ex;
                return(Json(msg));
            }
        }