示例#1
0
        public ActionResult Save(
            HttpPostedFile image,
            string Name,
            string Description,
            string Category,
            DateTime PublisDate,
            string ISBN,
            string Prices,
            string InStok,
            string Auther,
            string Pulisher
            )
        {
            BookValidation validation = new BookValidation();

            BookStore.Entites.Domain.Pulisher publisher = this.pulisherDataStore.Load(int.Parse(Pulisher));
            Auther   auther          = this.autherDataStore.Load(int.Parse(Auther));
            Category category        = this.categoryDataStore.Load(int.Parse(Category));
            string   imageuploadpath = "";

            if (image != null)
            {
                imageuploadpath = Server.MapPath(XmlConfigurator.GetSetting().PictureUploadFolder + Guid.NewGuid() + image.FileName);

                ///http://www.cs.tut.fi/~jkorpela/forms/file.html
                ///form üzerinde image yada farklı türde veri almak için bakılması önerilir.
                image.SaveAs(imageuploadpath);
            }

            Book book = new Book
            {
                Name        = Name,
                Description = Description,
                InStok      = (InStok == null ? false : true),
                ISBN        = ISBN,
                PublisDate  = PublisDate,
                Pulisher    = publisher,
                Auther      = auther,
                PicturePath = imageuploadpath,
            };

            /// veri katmanında(Data), bu şekilde (kategori ekleme) fonksiyonları hazırlanması
            /// kodlama esnasında kolaylıklar sağlamaktadır.
            book.AddToCategoriy(category); /// Book nesnesine dahil olmasını istediğimiz kategoriye ekliyoruz.

            //Kullanıcı istenildiği gibi nesne içeriğini doldurup / doldurmadığını
            //kontrol etmektedir.
            if (validation.Validate(book).IsValid)
            {
                this.bookdatastore.Insert(book);

                return(RedirectToAction("List"));
            }

            Session["Error"] = "Lütfen gerekli alanları doldurunuz...";

            return(RedirectToAction("Add"));
        }