示例#1
0
        public ActionResult SaveBook(ViewModels.Book book)
        {
            DomainModels.Book bookToSave = null;
            var service = ResolveService <IBookService>();

            if (book._state.Equals("modified", StringComparison.CurrentCultureIgnoreCase))
            {
                bookToSave = service.GetByID(book.ID);
            }
            service.SaveBook(book.CopyToDomainModel(bookToSave));

            return(Json(new JsonResultData {
                Success = true
            }));
        }
示例#2
0
        public static ViewModels.Book CopyToViewModel(this DomainModels.Book domainModel, ViewModels.Book viewModel = null)
        {
            if (viewModel == null)
            {
                viewModel = new ViewModels.Book();
            }

            viewModel.ID              = domainModel.ID;
            viewModel.Name            = domainModel.Name;
            viewModel.MainTitle       = domainModel.MainTitle;
            viewModel.MinorTitle      = domainModel.MinorTitle;
            viewModel.OfficialPrice   = domainModel.OfficialPrice;
            viewModel.SellingPrice    = domainModel.SellingPrice.GetValueOrDefault();
            viewModel.AccountPrice    = domainModel.AccountPrice.GetValueOrDefault();
            viewModel.PublicationDate = domainModel.PublicationDate;
            viewModel.PrintingTime    = domainModel.PublicationDate;
            viewModel.ISBN            = domainModel.ISBN;
            viewModel.Picture         = domainModel.Picture;
            viewModel.Thumbnail       = domainModel.Thumbnail;
            viewModel.PageNum         = domainModel.PageNum;
            viewModel.Language        = domainModel.Language;
            viewModel.SalesVolume     = domainModel.SalesVolume.GetValueOrDefault();
            viewModel.Introduction    = domainModel.Introduction;
            viewModel.Catalog         = domainModel.Catalog;
            viewModel.Digest          = domainModel.Digest;
            viewModel.PromotedOnFront = domainModel.PromotedOnFront;
            viewModel.ShowOnBanner    = domainModel.ShowOnBanner;
            viewModel.OnSale          = domainModel.OnSale;
            viewModel.AddedTime       = domainModel.AddedTime.GetValueOrDefault();
            viewModel.StorageTime     = domainModel.StorageTime.GetValueOrDefault();

            viewModel.AuthorIDs   = domainModel.Authors == null ? null : (from a in domainModel.Authors select a.ID).ToArray();
            viewModel.AuthorNames = domainModel.Authors == null ? null : (from a in domainModel.Authors select a.Name).ToArray();
            viewModel.PressIDs    = domainModel.Presses == null ? null :(from p in domainModel.Presses select p.ID).ToArray();
            viewModel.PressNames  = domainModel.Presses == null ? null : (from p in domainModel.Presses select p.Name).ToArray();
            viewModel.CategoryID  = domainModel.Category.ID;
            viewModel.Category    = domainModel.Category.Name;

            return(viewModel);
        }
示例#3
0
        public static DomainModels.Book CopyToDomainModel(this ViewModels.Book viewModel, DomainModels.Book domainModel = null)
        {
            if (domainModel == null)
            {
                domainModel = new DomainModels.Book();
            }

            domainModel.ID              = viewModel.ID;
            domainModel.Name            = viewModel.Name;
            domainModel.MainTitle       = viewModel.MainTitle;
            domainModel.MinorTitle      = viewModel.MinorTitle;
            domainModel.OfficialPrice   = viewModel.OfficialPrice;
            domainModel.SellingPrice    = viewModel.SellingPrice;
            domainModel.PublicationDate = viewModel.PublicationDate;
            domainModel.PrintingTime    = viewModel.PublicationDate;
            domainModel.ISBN            = viewModel.ISBN;
            domainModel.Picture         = viewModel.Picture;
            domainModel.Thumbnail       = viewModel.Thumbnail;
            domainModel.PageNum         = viewModel.PageNum;
            domainModel.Language        = viewModel.Language;
            domainModel.Introduction    = viewModel.Introduction;
            domainModel.Catalog         = viewModel.Catalog;
            domainModel.Digest          = viewModel.Digest;
            domainModel.State           = viewModel._state.Equals("added", StringComparison.CurrentCultureIgnoreCase) ? DomainModels.EntityState.Add :
                                          viewModel._state.Equals("removed", StringComparison.CurrentCultureIgnoreCase) ? DomainModels.EntityState.Delete : DomainModels.EntityState.Modify;

            var service = ContainerManager.Current.Resolve <IBookService>();

            domainModel.Category = ContainerManager.Current.Resolve <IBookCategoryService>().GetByID(viewModel.CategoryID);
            domainModel.Presses  = (from id in viewModel.PressIDs
                                    select ContainerManager.Current.Resolve <IPressService>().GetById(id)).ToList();
            domainModel.Authors = (from id in viewModel.AuthorIDs
                                   select ContainerManager.Current.Resolve <IAuthorService>().GetByID(id)).ToList();

            return(domainModel);
        }