コード例 #1
0
 private Photographer ToPhotographer(PhotographerView view)
 {
     return(new Photographer
     {
         Category = view.Category,
         CategoryId = view.CategoryId,
         Description = view.Description,
         Image = view.Image,
         IsActivte = view.IsActivte,
         LastEvent = view.LastEvent,
         PhotographerId = view.PhotographerId,
         Price = view.Price,
         Remarks = view.Remarks,
         Stock = view.Stock,
     });
 }
コード例 #2
0
        public async Task <ActionResult> Create(PhotographerView view)
        {
            if (ModelState.IsValid)
            {
                var pic    = string.Empty;
                var folder = "~/Content/Images";

                if (view.ImageFile != null)
                {
                    pic = FilesHelper.UploadPhoto(view.ImageFile, folder);
                    pic = string.Format("{0}/{1}", folder, pic);
                }

                var photographer = ToPhotographer(view);
                photographer.Image = pic;
                db.Photographers.Add(photographer);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Descripcion", view.CategoryId);
            return(View(view));
        }