Exemplo n.º 1
0
        public async Task <IActionResult> insert_mtr(IList <IFormFile> selectFile, string mtr_tm, string mtr_code, string mtr_name, string mtr_detail, string mtr_shelf, string mtr_unit_get, string mtr_keep_num, string mtr_unit_expose, string mtr_width, string mtr_long, string mtr_side, string mtr_roll, string mtr_noti, string mtr_noti_min, string mtr_noti_max, string mtr_sticker)
        {
            MaterialModel mtr = new MaterialModel();



            var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "material_img");
            int num     = selectFile.Count();

            if (num != 0)
            {
                foreach (var file in selectFile)
                {
                    if (file.Length > 0)
                    {
                        var filePath = Path.Combine(uploads, file.FileName);
                        mtr.mtr_img = file.FileName;

                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }
                    }
                    else
                    {
                        mtr.mtr_img = "nopicture.jpg";
                    }
                }
            }
            else
            {
                mtr.mtr_img = "nopicture.jpg";
            }



            mtr.mtr_ref_tm_id   = mtr_tm;
            mtr.mtr_code        = mtr_code;
            mtr.mtr_name        = mtr_name;
            mtr.mtr_detail      = mtr_detail;
            mtr.mtr_shelf       = mtr_shelf;
            mtr.mtr_unit_get    = mtr_unit_get;
            mtr.mtr_keep_num    = mtr_keep_num;
            mtr.mtr_unit_expose = mtr_unit_expose;
            mtr.mtr_width       = mtr_width;
            mtr.mtr_long        = mtr_long;
            mtr.mtr_side        = mtr_side;
            mtr.mtr_roll        = mtr_roll;
            mtr.mtr_noti        = mtr_noti;
            mtr.mtr_noti_min    = mtr_noti_min;
            mtr.mtr_noti_max    = mtr_noti_max;
            mtr.mtr_sticker     = mtr_sticker;

            mtr.insert_mtr();


            return(RedirectToAction("material", "Material"));
        }