public async Task <IActionResult> Create(BundleViewModel bundleViewModel) { if (ModelState.IsValid) { string photo = "No File"; if (bundleViewModel.Photo != null) { string uniqueFileName = null; string stringCutted = bundleViewModel.Photo.FileName.Split('.').Last(); uniqueFileName = Guid.NewGuid().ToString() + "." + stringCutted; photo = uniqueFileName; InputFile fileUpload = new InputFile(_hostingEnvironment); fileUpload.Uploadfile("files/bundle_images", bundleViewModel.Photo, photo); } var bundle = new Bundle { Name = bundleViewModel.Name, PhotoName = photo }; _context.Add(bundle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bundleViewModel)); }
public ActionResult Index(int?page = null) { //throw new NullReferenceException(); ViewBag.IsSuccess = false; ViewBag.IsDisplayContent = false; page = page ?? 1; if (page == 2) { ViewBag.IsDisplayContent = true; } #region Bundle View Model var bundleViewModel = new BundleViewModel() { PageViewModel = _pageRepository.GetPage(page), VideoCategoryViewModels = _videoRepository.GetVideoCategories(), FeaturedViewModels = _videoRepository.GetFeaturedVideos(), WhatsHotViewModels = _videoRepository.GetHotVideos(), LatestUpdatedViewModels = _videoRepository.GetLatestUpdatedVideos() }; #endregion return(View(bundleViewModel)); }
// GET: Bundle/Details/5 public ActionResult AdminDetails(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Bundle bundle = db.bundles.Find(id); if (bundle == null) { return(HttpNotFound()); } var model = new BundleViewModel { Id = bundle.Id, Country = bundle.Country, Category = bundle.Category, Valuta = bundle.Valuta, Customer = bundle.Customer, TrackNumber = bundle.TrackNumber, Description = bundle.Description, Price = bundle.Price, Orders = db.orders.Where(w => w.BundleId == bundle.Id).ToList(), Statuses = bundle.Statuses.ToList(), isPaid = bundle.isPaid, Invoice = bundle.InvoiceFilePath, BundleQuantity = bundle.BundleQuantity, OrderDate = bundle.CreatedDate }; return(View(model)); }
public ActionResult Save(Bundle bundle) { if (!ModelState.IsValid) { var viewModel = new BundleViewModel(bundle) { Types = _context.Types.ToList() }; return(View("BundleForm", viewModel)); } if (bundle.Id == 0) { _context.Bundles.Add(bundle); } else { var bundleInDb = _context.Bundles.Single(m => m.Id == bundle.Id); bundleInDb.Name = bundle.Name; bundleInDb.TypeId = bundle.TypeId; bundleInDb.NumberInStock = bundle.NumberInStock; bundleInDb.Size = bundle.Size; bundleInDb.Cost = bundle.Cost; } _context.SaveChanges(); return(RedirectToAction("Index", "Bundles")); }
public ActionResult Add(Guid siteId, BundleViewModel model) { if (ModelState.IsValid) { if (model.SiteId != siteId) { return(View("Error")); } var userId = User.Identity.GetUserId(); var site = Context.Sites.SingleOrDefault(x => x.Id == siteId && x.UserId == userId); var bundle = new Bundle { Type = (BundleType)Enum.Parse(typeof(BundleType), model.Type), Description = model.Description, Site = site }; Context.Bundles.Add(bundle); Context.SaveChanges(); return(RedirectToRoute("Default", new { controller = "Sites", action = "Details", Id = site.Id })); } populateBundleTypeSelectList(); return(View(model)); }
public List <BundleViewModel> Match(List <Bundle> bundle) { PackageNumberBL _packageNumberService = new PackageNumberBL(); List <BundleViewModel> _results = new List <BundleViewModel>(); ShipmentBL shipment = new ShipmentBL(); //UserBL _userService = new UserBL(); UserStore _userService = new UserStore(); foreach (Bundle _bundle in bundle) { BundleViewModel model = new BundleViewModel(); string _airwaybill = ""; try { _airwaybill = _packageNumberService.FilterActive().Find(x => x.PackageNo == _bundle.Cargo).Shipment.AirwayBillNo; }catch (Exception) { continue; } BundleViewModel isExist = _results.Find(x => x.AirwayBillNo == _airwaybill); if (isExist != null) { isExist.Qty++; //_results.Add(isExist); } else { model.AirwayBillNo = _airwaybill; List <Shipment> list = shipment.FilterActive().Where(x => x.AirwayBillNo == _airwaybill).ToList(); foreach (Shipment ship in list) { model.Shipper = ship.Shipper.FullName; model.Consignee = ship.Consignee.FullName; model.Address = ship.Consignee.Address1; model.CommodityType = ship.Commodity.CommodityType.CommodityTypeName; model.Commodity = ship.Commodity.CommodityName; model.Qty++; model.AGW += ship.Weight; model.ServiceMode = ship.ServiceMode.ServiceModeName; model.PaymendMode = ship.PaymentMode.PaymentModeName; model.Area = ship.OriginCity.CityName; model.CreatedDate = ship.CreatedDate; model.Destination = ship.DestinationCity.CityName; model.BSO = ship.OriginCity.CityName; } model.SackNo = _bundle.SackNo; model.BCO = _bundle.BranchCorpOffice.BranchCorpOfficeName; //model.Scannedby = AppUser.User.Employee.FullName; model.Scannedby = "N/A"; //string employee = _userService.FilterActive().Find(x => x.UserId == _bundle.CreatedBy).Employee.FullName; string employee = _userService.FindById(_bundle.CreatedBy).Employee.FullName; if (employee != "") { model.Scannedby = employee; } _results.Add(model); } } return(_results); }
public ActionResult Navigation() { var menuViewModel = new BundleViewModel() { PageViewModels = _pageRepository.GetPages(), VideoCategoryViewModels = _videoRepository.GetVideoCategories() }; return(PartialView("Partials/_Navigation", menuViewModel)); }
protected override DriverResult Editor(BundlePart part, IUpdateModel updater, dynamic shapeHelper) { var model = new BundleViewModel(); updater.TryUpdateModel(model, Prefix, null, null); if (part.ContentItem.Id != 0) { _bundleService.UpdateBundleProducts(part.ContentItem, model.Products); } return(Editor(part, shapeHelper)); }
public async Task <IActionResult> Edit(int id, BundleViewModel bundleViewModel) { if (id != bundleViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { InputFile fileUpload = new InputFile(_hostingEnvironment); var bundle = new Bundle { Id = bundleViewModel.Id, Name = bundleViewModel.Name, PhotoName = bundleViewModel.OldPhotoName }; if (bundleViewModel.Photo != null) { string uniqueFileName = null; string stringCutted = bundleViewModel.Photo.FileName.Split('.').Last(); uniqueFileName = Guid.NewGuid().ToString() + "." + stringCutted; bundle.PhotoName = uniqueFileName; if (bundleViewModel.OldPhotoName.ToLower() == "no file") { fileUpload.Uploadfile("files/bundle_images", bundleViewModel.Photo, uniqueFileName); } else { fileUpload.Updatefile("files/bundle_images", bundleViewModel.Photo, bundleViewModel.OldPhotoName, uniqueFileName); } } try { _context.Update(bundle); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BundleExists(bundle.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bundleViewModel)); }
public ViewResult New() { var types = _context.Types.ToList(); var sizes = _context.Sizes.ToList(); var viewModel = new BundleViewModel { Types = types, Sizes = sizes }; return(View("BundleForm", viewModel)); }
public ActionResult Dialog(string snippet) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(snippet); List <string> scripts = new List <string>(); if (doc.DocumentNode.SelectNodes("//script") != null) { foreach (var scriptNode in doc.DocumentNode.SelectNodes("//script")) { var scriptsource = scriptNode.Attributes["src"].Value; if (!scriptsource.StartsWith("~")) { scriptsource = "~" + scriptsource; } scripts.Add(scriptsource); } } List <string> stylesheets = new List <string>(); if (doc.DocumentNode.SelectNodes("//link") != null) { foreach (var linkNode in doc.DocumentNode.SelectNodes("//link")) { var stylesheetlink = linkNode.Attributes["href"].Value; if (!stylesheetlink.StartsWith("~")) { stylesheetlink = "~" + stylesheetlink; } stylesheets.Add(stylesheetlink); } } BundleViewModel m = new BundleViewModel(); m.VirtualPath = "~/bundles/"; if (scripts.Any()) { m.Files = scripts; } else { m.Files = stylesheets; } return(View(Config.DialogViewPath, m)); }
public ActionResult Edit(int id) { var bundle = _context.Bundles.Include(b => b.Type).Include(b => b.Size).SingleOrDefault(b => b.Id == id); if (bundle == null) { return(HttpNotFound()); } var viewModel = new BundleViewModel(bundle) { Types = _context.Types.ToList(), Sizes = _context.Sizes.ToList() }; return(View("BundleForm", viewModel)); }
public static void SaveBundleFromViewModel(BundleViewModel bundle, string bundleType) { var doc = XDocument.Load(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); var bundleEl = new XElement(bundleType + "Bundle"); if (doc.Descendants(bundleType + "Bundle").Any(x => x.Attribute("virtualPath").Value == bundle.VirtualPath)) { bundleEl = doc.Descendants(bundleType + "Bundle") .Single(x => x.Attribute("virtualPath").Value == bundle.VirtualPath); } else { bundleEl.SetAttributeValue("virtualPath", bundle.VirtualPath); doc.Descendants("bundles").Single().Add(bundleEl); } bundleEl.SetAttributeValue("disableMinification", bundle.DisableMinification.ToString()); bundleEl.Elements().Remove(); if (bundle.Files != null) { foreach (var file in bundle.Files) { var includeEl = new XElement("include"); includeEl.SetAttributeValue("virtualPath", file); bundleEl.Add(includeEl); } } doc.Save(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); try { //HttpRuntime.UnloadAppDomain(); var webConfigPath = HttpContext.Current.Request.PhysicalApplicationPath + "\\\\Web.config"; System.IO.File.SetLastWriteTimeUtc(webConfigPath, DateTime.UtcNow); } catch (Exception ex) { LogHelper.Info <Bundles>("Optimus failed to restart the application pool, you may need to check permissions on web.config"); } }
public BundleViewModel GetRecommendedBundle(IEnumerable <BundleConfigModel> bundles, AnswerModel answer) { var validList = new List <BundleConfigModel>(); foreach (var x in bundles) { if (BundleConditionFactory.Get(x.RuleId).IsValid(answer).Count() == 0) { validList.Add(x); } } if (validList.Count > 0) { var recommended = validList.OrderByDescending(x => x.Value).First(); var viewModel = new BundleViewModel() { Success = true, Bundle = _bundleRepository.GetBundle(recommended.BundleId) }; foreach (var b in recommended.ProductId) { viewModel.Products.Add(_productRepository.Get(b)); } return(viewModel); } var errorViewModel = new BundleViewModel() { Success = false, Errors = new List <string> { "Not found by given answer" } }; return(errorViewModel); }
public ActionResult AdminCreate(IEnumerable <int> selecteds) { try { var model = new BundleViewModel(); List <Order> orders = db.orders.Where(w => w.BundleId == 0 && selecteds.Contains(w.Id) && w.isPaid == true).ToList(); model.Orders = orders; foreach (var item in orders) { if (item.customer.CustomerNumber != orders[0].customer.CustomerNumber || item.category.Id != orders[0].category.Id || item.country.Id != orders[0].country.Id) { return(HttpNotFound()); } } return(PartialView(model)); } catch (Exception) { } return(HttpNotFound()); }
protected override DriverResult Editor(BundlePart part, IUpdateModel updater, dynamic shapeHelper) { var model = new BundleViewModel(); if (updater.TryUpdateModel(model, Prefix, null, null)) { if (part.ContentItem.Id != 0) { var updateResults = _bundleService.UpdateBundleProducts(part.ContentItem, model.Products); foreach (var error in updateResults.Errors) { updater.AddModelError("", error); } foreach (var warning in updateResults.Warnings) { _orchardServices.Notifier.Warning(warning); } } } return(Editor(part, shapeHelper)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var bundle = await _context.Bundles.FirstOrDefaultAsync(m => m.Id == id); if (bundle == null) { return(NotFound()); } var bundleViewModel = new BundleViewModel { Id = bundle.Id, Name = bundle.Name, OldPhotoName = bundle.PhotoName }; return(View(bundleViewModel)); }
public static void SaveBundleFromViewModel(BundleViewModel bundle, string bundleType) { var doc = XDocument.Load(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); var bundleEl = new XElement(bundleType + "Bundle"); if (doc.Descendants(bundleType + "Bundle").Any(x => x.Attribute("virtualPath").Value == bundle.VirtualPath)) { bundleEl = doc.Descendants(bundleType + "Bundle") .Single(x => x.Attribute("virtualPath").Value == bundle.VirtualPath); } else { bundleEl.SetAttributeValue("virtualPath", bundle.VirtualPath); doc.Descendants("bundles").Single().Add(bundleEl); } bundleEl.SetAttributeValue("disableMinification", bundle.DisableMinification.ToString()); bundleEl.Elements().Remove(); if (bundle.Files != null) { foreach (var file in bundle.Files) { var includeEl = new XElement("include"); includeEl.SetAttributeValue("virtualPath", file); bundleEl.Add(includeEl); } } doc.Save(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); HttpRuntime.UnloadAppDomain(); }
public BundleViewModel GetVideoBundleByCategoryId(int categoryId) { #region Video Category var videoCategoryViewModel = _dbContext.VideoCategories.Select(p => new VideoCategoryViewModel { VideoCategoryId = p.VideoCategoryId, Name = p.Name, Image = p.Image, VideoViewModels = p.Videos.Select(o => new VideoViewModel() { VideoId = o.VideoId, VideoCategoryId = o.VideoCategoryId, Title = o.Title, Description = o.Description, URL = o.URL, IsFeatured = o.IsFeatured ?? false, IsHot = o.IsHot ?? false, Image = o.Image, CreatedDate = o.CreatedDate }).ToList() }).Where(p => p.VideoCategoryId == categoryId).FirstOrDefault(); #endregion #region Video Categories var videoCategoryViewModels = _dbContext.VideoCategories.Select(p => new VideoCategoryViewModel { VideoCategoryId = p.VideoCategoryId, Name = p.Name, VideoViewModels = p.Videos.Select(o => new VideoViewModel() { VideoId = o.VideoId, VideoCategoryId = o.VideoCategoryId, Title = o.Title, Description = o.Description, URL = o.URL, IsFeatured = o.IsFeatured ?? false, IsHot = o.IsHot ?? false, Image = o.Image, CreatedDate = o.CreatedDate }).ToList() }).ToList(); #endregion #region Latest Updated Videos var dateYesterday = DateTime.Today.AddDays(-1); var dateToday = DateTime.Today; var latestUpdatedVideoModels = _dbContext.Videos.Select(o => new VideoViewModel() { VideoId = o.VideoId, VideoCategoryId = o.VideoCategoryId, Title = o.Title, Description = o.Description, URL = o.URL, IsFeatured = o.IsFeatured ?? false, IsHot = o.IsHot ?? false, Image = o.Image, CreatedDate = o.CreatedDate }).ToList(); //.Where(p => DateTime.Compare(p.CreatedDate ?? dateYesterday, dateToday) < 2).ToList(); #endregion BundleViewModel bundleViewModel = new BundleViewModel() { VideoCategoryViewModel = videoCategoryViewModel, VideoCategoryViewModels = videoCategoryViewModels, LatestUpdatedViewModels = latestUpdatedVideoModels }; return(bundleViewModel); }
public ActionResult Bundle(int?BundleID) { if (BundleID != null || BundleID < 0) { var bundle = db.Bundles.Where(i => i.BundleID == BundleID).FirstOrDefault(); if (bundle != null && bundle.Offers != null && bundle.Offers.Count() > 0) { List <OfferPicture> MainPictures = new List <OfferPicture>(); foreach (var offer in bundle.Offers) { MainPictures.Add(offer.OfferPictures.First()); } BundleViewModel BundleViewModel = new BundleViewModel() { Bundle = bundle, OffersList = bundle.Offers.ToList(), MainPictures = MainPictures }; var user = db.Users.Where(i => i.Login == HttpContext.User.Identity.Name).FirstOrDefault(); if (user != null) { bool?isinbucket = user.Bucket.BucketItems?.Where(i => i.Offer == null).Select(i => i.Bundle).ToList().Contains(bundle); bool?isinfavourite = user.FavouriteOffer?.Where(i => i.Offer == null).Select(i => i.Bundle).ToList().Contains(bundle); List <int> InFavouriteOffersIDs = new List <int>(); List <int> InBucketOffersIDs = new List <int>(); foreach (var favOffer in user.FavouriteOffer) { if (favOffer != null && favOffer.Offer != null) { InFavouriteOffersIDs.Add(favOffer.Offer.OfferID); } } foreach (var BucketItem in user.Bucket.BucketItems) { if (BucketItem != null && BucketItem.Offer != null) { InBucketOffersIDs.Add(BucketItem.Offer.OfferID); } } BundleViewModel.InFavouriteOffersIDs = InFavouriteOffersIDs; BundleViewModel.InBucketOffersIDs = InBucketOffersIDs; BundleViewModel.IsInFavourite = isinfavourite ?? false; BundleViewModel.IsInBucket = isinbucket ?? false; } return(View(BundleViewModel)); } else { return(new HttpStatusCodeResult(500)); } } else { return(new HttpStatusCodeResult(404)); } }
public void PostBundleUpdate(BundleViewModel bundle, string bundleType) { Bundles.SaveBundleFromViewModel(bundle, bundleType); }