public AddOfferPage() { InitializeComponent(); AddOfferViewModel viewModel = new AddOfferViewModel(); BindingContext = viewModel; }
public async Task <Offer> AddOffer(AddOfferViewModel offer) { var newOffer = new Offer() { Id = Guid.NewGuid(), ShipmentNumber = GenerateRunningNo(), Currency = offer.Currency, DeliveryDateTime = offer.DeliveryDateTime, DeliveryLocationName = offer.DeliveryLocationName, LoadDetail1 = offer.LoadDetail1, LoadDetail2 = offer.LoadDetail2, LoadDetail3 = offer.LoadDetail3, PickupDateTime = offer.PickupDateTime, PickupLocationName = offer.PickupLocationName, Price = offer.Price, VehicleBuildUp = offer.VehicleBuildUp, VehicleSize = offer.VehicleSize }; _context.Add(newOffer); if (await _context.SaveChangesAsync() > 0) { return(newOffer); } return(null); }
public MainPageViewModel() { SearchViewModel = new SearchViewModel(); NewestOffersViewModel = new NewestOffersViewModel(); AddOfferViewModel = new AddOfferViewModel(); AccountViewModel = new AccountViewModel(); }
public ActionResult AddOffer(AddOfferViewModel vm) { AddNewOfferToDatabase(vm.Offer); List <Offer> offers = Manager.Instance.GetAllOffers(); return(View("Index", offers)); }
public ActionResult AddOffer() { Offer o = new Offer(); var lm = GetDropDrown(); AddOfferViewModel vm = new AddOfferViewModel { Offer = o, ListStatuses = lm }; return(View("AddOffer", vm)); }
async void addOffer_Clicked(object sender, EventArgs e) { string title = titleEntry.Text; string description = descriptionEntry.Text; int categoryId = Convert.ToInt32(((Category)CategoryBinder.SelectedItem).CategoryID); int quantity = Convert.ToInt32(quantityEntry.Text); string price = priceEntry.Text; OfferState state = (OfferState)StateBinder.SelectedItem; var offerItem = new Models.BindingModels.OfferBindingModel { Title = title, Description = description, CategoryID = categoryId, InStockOriginaly = quantity, Price = price, UserID = Session.user.UserID, OfferState = state }; if (string.IsNullOrEmpty(titleEntry.Text) || string.IsNullOrEmpty(descriptionEntry.Text)) { await DisplayAlert("Enter data", "Enter valid data", "Ok"); } else { try { OfferItem response = await AddOfferViewModel.AddOfferAsync(offerItem); if (response != null) { output.Text = "Oferta dodana pomyślnie!"; } else { } } catch (AggregateException err) { foreach (var errInner in err.InnerExceptions) { Debug.WriteLine(errInner); //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary } ; } } }
public ActionResult AddOffer() { if ((string)Session["userCode"] == "vendor") { int VendorId = (int)Session["VendorId"]; var d = (from c in entity.Vendors where c.VendorId == VendorId select c).FirstOrDefault(); AddOfferViewModel aovm = new AddOfferViewModel(); aovm.CountryId = Convert.ToInt32(d.CountryId); aovm.CityId = Convert.ToInt32(d.CityId); aovm.VendorId = Convert.ToInt32(d.VendorId); aovm.OfferTypeList = new SelectList(entity.OfferTypes, "OfferTypeId", "OfferTypeName"); return(View(aovm)); } else { Session["message"] = "please log in to add your offer."; return(RedirectToAction("Index", "Home")); } }
public async Task <ActionResult> AddOffer(AddOfferViewModel offer) { if (offer.PickupDateTime >= offer.DeliveryDateTime) { return(new BadRequestObjectResult("Pickup date time should be earlier than delivery date time")); } if (!_vehicleSize.Contains(offer.VehicleSize)) { return(new BadRequestObjectResult("Vehicle size only accept 1TON, 3TON, 5TON or 10TON")); } if (!_vehicleBuildUp.Contains(offer.VehicleBuildUp)) { return(new BadRequestObjectResult("Vehicle build up only accept Hardbox truck, Canvas truck or Open truck")); } if (!_states.Contains(offer.PickupLocationName)) { return(new BadRequestObjectResult("Pickup location only allow states in Peninsula Malaysia")); } if (!_states.Contains(offer.DeliveryLocationName)) { return(new BadRequestObjectResult("Delivery location only allow states in Peninsula Malaysia")); } var result = await _offerService.AddOffer(offer); if (result != null) { return(new CreatedAtRouteResult("GetOfferByShipNumber", new { shipmentNumber = result.ShipmentNumber })); } return(new BadRequestObjectResult("Problem adding the offer")); }
public async Task <ActionResult> Index(OfferViewModel Offer, List <OfferProductViewModel> Products, List <OfferPackageViewModel> Packages) { try { AddOfferViewModel model = new AddOfferViewModel(); model.Offer = Offer; model.Products = Products; model.Packages = Packages; model.Offer.Description = model.Offer.Description ?? ""; if (!ModelState.IsValid) { return(View(ModelState)); } if (model.Products == null && model.Packages == null) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Please select products or packages to add")); } List <OfferProductViewModel> offer_products = new List <OfferProductViewModel>(); List <OfferPackageViewModel> offer_packages = new List <OfferPackageViewModel>(); if (model.Products != null) { offer_products = model.Products.Where(x => x.IsChecked).ToList(); } if (model.Packages != null) { offer_packages = model.Packages.Where(x => x.IsChecked).ToList(); } if (offer_packages.Count == 0 && offer_products.Count == 0) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Please select products or packages to add")); } MultipartFormDataContent content; bool FileAttached = (Request.RequestContext.HttpContext.Session["AddOfferImage"] != null); bool ImageDeletedOnEdit = false; var imgDeleteSessionValue = Request.RequestContext.HttpContext.Session["ImageDeletedOnEdit"]; if (imgDeleteSessionValue != null) { ImageDeletedOnEdit = Convert.ToBoolean(imgDeleteSessionValue); } byte[] fileData = null; var ImageFile = (HttpPostedFileWrapper)Request.RequestContext.HttpContext.Session["AddOfferImage"]; if (FileAttached) { using (var binaryReader = new BinaryReader(ImageFile.InputStream)) { fileData = binaryReader.ReadBytes(ImageFile.ContentLength); } } ByteArrayContent fileContent; JObject response; bool firstCall = true; callAgain : content = new MultipartFormDataContent(); if (FileAttached) { fileContent = new ByteArrayContent(fileData); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = ImageFile.FileName }; content.Add(fileContent); } if (model.Offer.Id > 0) { content.Add(new StringContent(model.Offer.Id.ToString()), "Id"); } content.Add(new StringContent(model.Offer.Name), "Name"); content.Add(new StringContent(model.Offer.Store_Id.ToString()), "Store_Id"); content.Add(new StringContent(model.Offer.ValidFrom.ToString("dd/MM/yyyy hh:mm:ss tt")), "ValidFrom"); content.Add(new StringContent(model.Offer.ValidTo.ToString("dd/MM/yyyy hh:mm:ss tt")), "ValidTo"); content.Add(new StringContent(model.Offer.Description), "Description"); content.Add(new StringContent(Convert.ToString(ImageDeletedOnEdit)), "ImageDeletedOnEdit"); var offerProducts = JsonConvert.SerializeObject(offer_products); var offerPackages = JsonConvert.SerializeObject(offer_packages); var bufferProduct = System.Text.Encoding.UTF8.GetBytes(offerProducts); var byteContentProduct = new ByteArrayContent(bufferProduct); byteContentProduct.Headers.ContentType = new MediaTypeHeaderValue("application/json"); content.Add(byteContentProduct, "offer_products"); var bufferPackages = System.Text.Encoding.UTF8.GetBytes(offerPackages); var byteContentPackages = new ByteArrayContent(bufferPackages); byteContentPackages.Headers.ContentType = new MediaTypeHeaderValue("application/json"); content.Add(byteContentPackages, "offer_packages"); response = await ApiCall.CallApi("api/Admin/AddOffer", User, isMultipart : true, multipartContent : content); if (firstCall && response.ToString().Contains("UnAuthorized")) { firstCall = false; goto callAgain; } else if (response.ToString().Contains("UnAuthorized")) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "UnAuthorized Error")); } if (response is Error) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, (response as Error).ErrorMessage)); } else { if (model.Offer.Id > 0) { TempData["SuccessMessage"] = "The offer has been updated successfully."; } else { TempData["SuccessMessage"] = "The offer has been added successfully."; } return(Json(new { success = true, responseText = "Success" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(new HttpStatusCodeResult(Utility.LogError(ex), "Internal Server Error")); } }
public ActionResult AddOffer(AddOfferViewModel aovm, HttpPostedFileBase AddPicture) { if (ModelState.IsValid) { try { bool result = ol.CheckVendorIdInOffer(aovm.VendorId); if (result == true) { result = ol.CheckTypeId(aovm.VendorId, aovm.OfferTypeId); if (result == true) { result = ol.CheckOverlap(aovm.OfferStartTime, aovm.OfferStopTime, aovm.VendorId, aovm.OfferTypeId); if (result == true) { TempData["Success"] = "At the same time you can't two offers of same type."; aovm.OfferTypeList = new SelectList(entity.OfferTypes, "OfferTypeId", "OfferTypeName"); return(View(aovm)); } } } result = ol.CheckNameExistance(aovm.OfferName, aovm.VendorId); if (result == true) { TempData["Success"] = "You have a same Offer in your List please check that"; aovm.OfferTypeList = new SelectList(entity.OfferTypes, "OfferTypeId", "OfferTypeName"); return(View(aovm)); } Offer offer = new Offer(); offer.OfferName = aovm.OfferName; offer.VendorId = aovm.VendorId; offer.CountryId = aovm.CountryId; offer.CityId = aovm.CityId; offer.OfferTypeId = aovm.OfferTypeId; offer.OfferPrice = aovm.OfferPrice; offer.OfferStartTime = Convert.ToDateTime(aovm.OfferStartTime); offer.OfferStopTime = Convert.ToDateTime(aovm.OfferStopTime); if (aovm.OfferDetail != null) { offer.OfferDetail = aovm.OfferDetail; } else { offer.OfferDetail = "Not given yet."; } offer.OfferStatus = true; offer.OfferAdminsPermit = true; offer.OfferDateOfAccountCreation = DateTime.Now; entity.Offers.Add(offer); Vendor vendor = (from c in entity.Vendors where c.VendorId == aovm.VendorId select c).FirstOrDefault(); vendor.VendorOfferStatus = true; if (entity.SaveChanges() > 0) { var p = (from c in entity.Offers where c.OfferName == aovm.OfferName && c.CountryId == aovm.CountryId && c.CityId == aovm.CityId select new { c.OfferId, c.CountryId, c.CityId }).FirstOrDefault(); if (AddPicture != null) { OfferAlbum pa = new OfferAlbum(); pa.OfferAlbumName = "Profile Picture"; pa.OfferId = p.OfferId; pa.AlbumTypeId = 1; pa.CityId = p.CityId; pa.CountryId = p.CountryId; pa.VendorId = aovm.VendorId; pa.OfferAlbumAdminPermit = true; pa.OfferAlbumPrivacy = true; pa.OfferAlbumDateOfAdded = DateTime.Now; entity.OfferAlbums.Add(pa); entity.SaveChanges(); OfferPicture pp = new OfferPicture(); pp.OfferPictureData = new byte[AddPicture.ContentLength]; AddPicture.InputStream.Read(pp.OfferPictureData, 0, AddPicture.ContentLength); pp.OfferId = p.OfferId; var albumId = (from c in entity.OfferAlbums where c.OfferId == p.OfferId && c.AlbumTypeId == 1 select c.OfferAlbumId).Single(); int AlbumId = Convert.ToInt32(albumId); pp.OfferAlbumId = AlbumId; pp.AlbumTypeId = 1; pp.OfferPictureAdminPermit = true; pp.CountryId = p.CountryId; pp.CityId = p.CityId; pp.VendorId = aovm.VendorId; pp.OfferPicturePrivacy = true; pp.OfferPictureDateOfAdded = DateTime.Now; entity.OfferPictures.Add(pp); if (entity.SaveChanges() > 0) { Offer o = (from c in entity.Offers where c.OfferId == p.OfferId select c).FirstOrDefault(); int pictureId = (from c in entity.OfferPictures where c.OfferId == p.OfferId && c.AlbumTypeId == 1 orderby c.OfferPictureId descending select c.OfferPictureId).First(); o.OfferProfilePicId = pictureId; entity.SaveChanges(); } } ModelState.Clear(); TempData["Success"] = "Added Successfully"; int VendorId = (int)Session["VendorId"]; var d = (from c in entity.Vendors where c.VendorId == VendorId select c).FirstOrDefault(); aovm.CountryId = Convert.ToInt32(d.CountryId); aovm.CityId = Convert.ToInt32(d.CityId); aovm.VendorId = Convert.ToInt32(d.VendorId); aovm.OfferTypeList = new SelectList(entity.OfferTypes, "OfferTypeId", "OfferTypeName"); return(View(aovm)); } else { aovm.OfferTypeList = new SelectList(entity.OfferTypes, "OfferTypeId", "OfferTypeName"); TempData["Success"] = "Error not Saved"; return(View(aovm)); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Offer", "AddOffer"))); } } else { aovm.OfferTypeList = new SelectList(entity.OfferTypes, "OfferTypeId", "OfferTypeName"); return(View(aovm)); } }