Exemplo n.º 1
0
        public ActionResult Edit(MaterialModel model, int id)
        {
            if (ModelState.IsValid)
            {
                var material = new JL.Core.Models.Material();
                material.AutoId       = id;
                material.Title        = model.Title;
                material.MaterialType = model.FileType;
                material.Description  = model.Description;

                material.Status = model.Status ? 0 : 1;

                // picture
                if (Request.Files != null &&
                    Request.Files.Count > 0 &&
                    Request.Files[0].ContentLength > 0)
                {
                    string picture, filename;
                    var    success = FileHelper.SaveMaterial(Request.Files[0], material.MaterialType, out filename, out picture);

                    if (success)
                    {
                        material.Picture  = picture;
                        material.FileName = filename;
                        material.Url      = model.FileName;
                    }

                    //for show
                    model.Picture  = picture;
                    model.FileName = filename;
                    model.Url      = filename;
                }

                jlService.UpdateMaterial(material);
                ViewData.Add("ResultObject", ResultObject.Succeed());
            }

            return(View(model));
        }