예제 #1
0
 public JsonResult Create([Bind(Include = "Name")] SellerCreateView seller)
 {
     if (ModelState.IsValid)
     {
         var sellerForSave = Mapper.Map <Seller>(seller);
         try
         {
             sellerService.AddSeller(sellerForSave);
             return(Json(new { result = true }));
         }
         catch (Exception e)
         {
             return(Json(new { result = false, message = e.Message }));
         }
     }
     return(Json(new { result = false, message = "Models is invalid" }));
 }
예제 #2
0
        public ActionResult RegisterSeller(SellerCreateView model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;

                // If the Photo property on the incoming model object is not null, then the user
                // has selected an image to upload.
                if (model.PhotoPath != null)
                {
                    // The image must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the inject
                    // HostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images");
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.PhotoPath.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    model.PhotoPath.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                Seller newseller = new Seller
                {
                    Sname         = model.Sname,
                    Password      = model.Password,
                    PostalAddress = model.PostalAddress,
                    Email         = model.Email,
                    Website       = model.Website,
                    Companyname   = model.Companyname,
                    Bankdetails   = model.Bankdetails,

                    // Store the file name in PhotoPath property of the employee object
                    // which gets saved to the Employees database table
                    PhotoPath = uniqueFileName
                };

                _context.Add(newseller);
                _context.SaveChanges();
                return(RedirectToAction("Details", new { id = newseller.Sid }));
            }

            return(View());
        }