예제 #1
0
        public ActionResult Edit(int Id)
        {
            VidlyDbFirstEntities1 db = new VidlyDbFirstEntities1();
            var retOneCustomer       = db.Customers.SingleOrDefault(c => c.Id == Id);

            if (retOneCustomer == null)
            {
                return(Content("No Customer with this Id"));
            }
            var viewModel = new CustomerMembershipType
            {
                Customer        = retOneCustomer,
                MembershipTypes = db.Membership_Type.ToList()
            };

            return(View("Edit", viewModel));
        }
예제 #2
0
        public ActionResult Create(Customer customer)//, HttpPostedFileBase PostedFile
        {
            try
            {
                if (ModelState.IsValid)

                {
                    VidlyDbFirstEntities1 dbsave = new VidlyDbFirstEntities1();
                    //saving image to project folder and path to db

                    var fileName  = Path.GetFileName(customer.PostedFile.FileName);                                                              //getting the file name and extension from the file above
                    var path      = Path.Combine(Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "Images/", fileName); // sets the image server path, the one with localhost/....
                    var localpath = Path.Combine(Server.MapPath("~/Images/") + fileName);                                                        // sets the image local path, the one with c:\\users...
                    customer.ImageUrl = path;                                                                                                    //sets the server path to imageUrl property b4 saving it in db

                    customer.PostedFile.SaveAs(localpath);                                                                                       //saves the image local path to the images folder in our project
                    customer.Image        = ReadFully(customer.PostedFile.InputStream);                                                          //inputStream is the method that allows you to read from the uploaded file;
                    customer.Content_Type = customer.PostedFile.ContentType;
                    var save = dbsave.Customers.Add(customer);
                    dbsave.SaveChanges();


                    return(RedirectToAction("index1", "Customer"));
                }
            }
            catch (DbEntityValidationException ex)
            {
                Console.WriteLine(ex);
            }
            //was trying to return the validation errors in viewdata, so i had to still use the view model here too, also to populate the membershiptype ddl
            ViewData["customer"] = customer;
            VidlyDbFirstEntities1 db = new VidlyDbFirstEntities1();
            var membershipType       = db.Membership_Type.ToList();
            var viewmodel            = new CustomerMembershipType {
                MembershipTypes = membershipType, Customer = customer
            };

            return(View("Create", viewmodel));
        }
예제 #3
0
 public Customer() : base()
 {
     this.Addresses      = new List <CustomerAddress>();
     this.MembershipType = CustomerMembershipType.None;
 }