public OfferModel CreateOffer(OfferModel offer) { // TODO Extract category & user logic from the controller and put it here.... // PRO: cleaning up the controller - it would not need to hold any reference to services other than offerService // CONTRA: this service would need to either hold a reference to user and category services // or to directly work with db, accessing the user and category repositories... // serious QUESTION! // Business logic offer.offer_status = OfferModel.OfferStatus.WAIT_FOR_APPROVING; offer.offer_created = DateTime.UtcNow; offer.offer_expires = offer.offer_created.AddDays(10); db.OffersRepository.Insert(offer); db.Save(); return(offer); }
public void CreateBid_ValidBids_ShouldCreateBidsCorrectly() { // Arrange -> clean database, register new user, create an offer TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); var offerModel = new OfferModel() { Title = "Title", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(5) }; var httpResultOffer = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offerModel.Title, offerModel.Description, offerModel.InitialPrice, offerModel.ExpirationDateTime); Assert.AreEqual(HttpStatusCode.Created, httpResultOffer.StatusCode); var offer = httpResultOffer.Content.ReadAsAsync <OfferModel>().Result; // Act -> create a few bids var bidsToAdds = new BidModel[] { new BidModel() { BidPrice = 250, Comment = "My initial bid" }, new BidModel() { BidPrice = 300, Comment = "My second bid" }, new BidModel() { BidPrice = 400, Comment = "My third bid" }, new BidModel() { BidPrice = 500 } }; foreach (var bid in bidsToAdds) { var httpResultBid = TestingEngine.CreateBidHttpPost(userSession.Access_Token, offer.Id, bid.BidPrice, bid.Comment); Assert.AreEqual(HttpStatusCode.OK, httpResultBid.StatusCode); } // Assert -> bids created successfully var bidsCount = TestingEngine.GetBidsCountFromDb(); Assert.AreEqual(4, bidsCount); }
public OfferModel GetCCompanyOffer(CustomerModel customer) { var company = _companyService.GetCompanies().ElementAt(2); int rndPrice = new Random().Next(100, 600); var offer = new OfferModel() { CompanyId = company.Id, CompanyLogo = company.Logo, CompanyName = company.Name, Description = "C Firması Teklif Tutarı", PlateNumber = customer.PlateNumber, Price = 300 + rndPrice }; return(offer); }
public ActionResult Index() { try { int Branch_ID = Convert.ToInt32(Session["Branvch_ID"]); var Fees = db.Fees.Where(i => i.Branch_ID == Branch_ID && i.Status == true).OrderByDescending(i => i.ID).ToList(); List <FeeStudentPlaneOfferModel> FeeStudentPlaneOfferModelList = new List <FeeStudentPlaneOfferModel>(); foreach (var Fee in Fees) { FeeStudentPlaneOfferModel FeeStudentPlaneOfferModel = new FeeStudentPlaneOfferModel(); FeeModel FeeModel = new FeeModel(); StudentModel StudentModel = new StudentModel(); PlaneModel PlaneModel = new PlaneModel(); OfferModel OfferModel = new OfferModel(); var Plane = db.Planes.Where(i => i.ID == Fee.Plane_ID).FirstOrDefault(); var Offer = db.Offers.Where(i => i.ID == Fee.Offer_ID).FirstOrDefault(); var Student = db.Students.Where(i => i.ID == Fee.Student_ID).FirstOrDefault(); FeeModel.ID = Fee.ID; FeeModel.Payment_Date = Fee.Payment_Date; FeeModel.Duration = Fee.Start_Date + " TO " + Fee.End_Date; PlaneModel.GST = Fee.GST; FeeModel.Payment_Amount = Fee.Payment_Amount; FeeModel.Discount_On_Bill = Fee.Discount_On_Bill; if (Offer != null) { OfferModel.Name = Offer.Name; } PlaneModel.Name = Plane.Name; PlaneModel.Worth = Plane.Worth; StudentModel.Full_Name = Student.First_Name + " " + Student.Last_Name; FeeStudentPlaneOfferModel.FeeModel = FeeModel; FeeStudentPlaneOfferModel.OfferModel = OfferModel; FeeStudentPlaneOfferModel.PlaneModel = PlaneModel; FeeStudentPlaneOfferModel.StudentModel = StudentModel; FeeStudentPlaneOfferModelList.Add(FeeStudentPlaneOfferModel); } return(View(FeeStudentPlaneOfferModelList)); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
private async Task <OfferModel> UpdateOfferImage(OfferModel result, OfferModel data) { if (result != null && data.Images != null) { var img = await this._imgRepo.GetImagesByIds(data.Images.Select(ss => ss.ID).ToList()); if (img != null && img.Count() > 0) { foreach (var item in img) { item.RefrenceID = data.ID; await this._imgRepo.Update(item); } } } return(data); }
public ActionResult CreateOffer(OfferModel offerModel) { if (!ModelState.IsValid) { return(View(offerModel)); } var merchant = _context.Merchants.FirstOrDefault(c => c.MerchantID == offerModel.OffererId); if (merchant != null) { offerModel.MerchantName = merchant.CompanyName; } Session["couponDetails"] = offerModel; //return RedirectToAction("Preview",offerModel); return(Preview(offerModel)); }
public void GetOfferDetails_Of_Existing_Offer_Should_Return_200Ok_And_Offer_Details() { // Arrange -> clean the database and register new user TestingEngine.CleanDatabase(); var userSession = TestingEngine.RegisterUser("peter", "pAssW@rd#123456"); // Act -> create a few offers var offersToAdds = new OfferModel[] { new OfferModel() { Title = "First Offer (Expired)", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(-5) }, new OfferModel() { Title = "Another Offer (Expired)", InitialPrice = 15.50m, ExpirationDateTime = DateTime.Now.AddDays(-1) }, new OfferModel() { Title = "Second Offer (Active 3 months)", Description = "Description", InitialPrice = 500, ExpirationDateTime = DateTime.Now.AddMonths(3) }, new OfferModel() { Title = "Third Offer (Active 6 months)", InitialPrice = 120, ExpirationDateTime = DateTime.Now.AddMonths(6) }, }; foreach (var offer in offersToAdds) { var httpResult = TestingEngine.CreateOfferHttpPost(userSession.Access_Token, offer.Title, offer.Description, offer.InitialPrice, offer.ExpirationDateTime); } var firstOfferId = TestingEngine.GetRandomOfferIdFromDb(); var getOfferDetailsHttpResult = TestingEngine.GetOfferDetailsHttpGet(firstOfferId); Assert.AreEqual(HttpStatusCode.OK, getOfferDetailsHttpResult.StatusCode); var offerDetails = getOfferDetailsHttpResult.Content.ReadAsAsync <GetOfferByDetailsViewModel>().Result; Assert.AreEqual(offersToAdds[0].Title, offerDetails.Title); Assert.AreEqual(offersToAdds[0].Description, offerDetails.Description); Assert.AreEqual(offersToAdds[0].InitialPrice, offerDetails.InitialPrice); //Assert.AreEqual(offersToAdds[0].ExpirationDateTime.ToString(), offerDetails.ExpirationDateTime.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual(0, offerDetails.BidsCount); Assert.IsTrue(offerDetails.IsExpired); }
public ActionResult Create() { try { int Branch_ID = Convert.ToInt32(Session["Branvch_ID"]); var Student = db.Students.Where(i => i.Branch_ID == Branch_ID).ToList(); List <StudentModel> StudentModelList = new List <StudentModel>(); foreach (var Full_Name in Student) { StudentModel StudentModel = new StudentModel(); StudentModel.Full_Name = Full_Name.First_Name + " " + Full_Name.Last_Name; StudentModel.ID = Full_Name.ID; StudentModelList.Add(StudentModel); } ViewBag.Student_NAME = StudentModelList; var Plane = db.Planes.Join(db.Branch_Wise_Plane, j => j.ID, u => u.Plane_ID, (j, u) => new { Branch_Plane = u, Plane = j }).Where(i => i.Branch_Plane.Branch_ID == Branch_ID && i.Branch_Plane.Status == true).ToList(); List <PlaneModel> PlaneModelList = new List <PlaneModel>(); foreach (var d in Plane) { PlaneModel planeModel = new PlaneModel(); planeModel.Name = d.Plane.Name; planeModel.ID = d.Plane.ID; PlaneModelList.Add(planeModel); } ViewBag.Planes_NAME = PlaneModelList; var Offer = db.Offers.Join(db.Branch_Wise_Offer, j => j.ID, u => u.Offer_ID, (j, u) => new { Branch_Wise_Offer = u, Offer = j }).Where(i => i.Branch_Wise_Offer.Branch_ID == Branch_ID && i.Branch_Wise_Offer.Status == true /*&& DbFunctions.TruncateTime(DateTime.Now) > DbFunctions.TruncateTime(i.Offer.Start_Date) && DbFunctions.TruncateTime(i.Offer.End_Date) > DbFunctions.TruncateTime(DateTime.Now)*/).ToList(); List <OfferModel> OfferModelList = new List <OfferModel>(); foreach (var d in Offer) { OfferModel OfferModel = new OfferModel(); OfferModel.Name = d.Offer.Name; OfferModel.ID = d.Offer.ID; OfferModelList.Add(OfferModel); } ViewBag.Offer_NAME = OfferModelList; return(View()); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
public void CreateOffer_Unauthorized_ShouldReturnUnauthorized() { // Arrange -> clean the database TestingEngine.CleanDatabase(); // Act -> try to create an offer var offer = new OfferModel() { Title = "Title", Description = "Description", InitialPrice = 200, ExpirationDateTime = DateTime.Now.AddDays(5) }; var httpResult = TestingEngine.CreateOfferHttpPost(null, offer.Title, offer.Description, offer.InitialPrice, offer.ExpirationDateTime); // Assert -> offer not created Assert.AreEqual(HttpStatusCode.Unauthorized, httpResult.StatusCode); var offersCount = TestingEngine.GetOffersCountFromDb(); Assert.AreEqual(0, offersCount); }
public OfferModel PutOffer(OfferModel offer, bool isBillCreated) { if (isBillCreated) { offer.AvailableOffers--; offer.BoughtOffers++; } else { offer.AvailableOffers++; offer.BoughtOffers--; } db.OfferModelRepository.Update(offer); db.Save(); return(offer); }
public ActionResult Offers(int id) { OfferServices serv = new OfferServices(); PagerModel pagerParameters = new PagerModel(); var offertF = new OfferModel() { UserId = PersonSessionId, }; if (id != 0 && id != 1) { offertF.OfferReceived = id == 2; } var results = serv.GetAll(pagerParameters, offertF); return(Json(results, JsonRequestBehavior.AllowGet)); }
public OfferModel UpdateOffer(OfferModel offer, bool isBillCreated) { if (isBillCreated) { offer.available_offers--; offer.bought_offers++; } else { offer.available_offers++; offer.bought_offers--; } db.OffersRepository.Update(offer); db.Save(); return(offer); }
public IHttpActionResult PutOfferModel(int id, OfferModel offerModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != offerModel.id) { return(BadRequest()); } db.OfferRepository.Update(offerModel); db.Save(); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostOfferModel(OfferModel offerModel) { // Omoguciti dodavanje i izmenu kategorije i prodavca iz ponude // Bez Foreign Key svojstava stvari su mnogo komplikovane.. // Sa Foreign Key JSON koji saljemo je znatno svedeniji ali je i logika bolja //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} //if (!ModelState.IsValid || offerModel.categoryId == null || offerModel.userModel == null) // Mladen's code: // You also need to update your Model classes. Mladen's solution is to use 'normal' property // names and map them to the 'wacky' database column names if (!ModelState.IsValid || offerModel.categoryId == null || offerModel.sellerId == null) { return(BadRequest(ModelState)); } CategoryModel category = categoryService.GetCategory((int)offerModel.categoryId); UserModel seller = userService.GetUser((int)offerModel.sellerId); if (category == null || seller == null) { return(NotFound()); } if (seller.user_role != UserModel.UserRoles.ROLE_SELLER) { return(BadRequest("User's role must be ROLE_SELLER")); } offerModel.category = category; offerModel.seller = seller; OfferModel createdOffer = offerService.CreateOffer(offerModel); // my old stuff // offerService.CreateOffer(offerModel); return(CreatedAtRoute("SingleOfferById", new { id = offerModel.id }, offerModel)); }
public bool SaveItemSpecificOfferDetails(OfferModel offerDetails) { try { if (offerDetails.Id > 0) { var offer = _couponManagmentRepository.GetOffers(offerDetails.CompanyCode, offerDetails.BranchCode).FirstOrDefault(x => x.Id == offerDetails.Id); Offer objOffer = new Offer(); List <OfferDetail> lstItemSpecificCoupons = new List <OfferDetail>(); SetOfferValuesBeforeSave(offerDetails, offer); int OfferId = _couponManagmentRepository.SaveOfferDetails(offer); //OfferDetail objOfferDetail = new OfferDetail(); //SetItemSpecificOfferDetails(offerDetails, objOfferDetail, OfferId, ref lstItemSpecificCoupons); //_couponManagmentRepository.SaveItemSpecificOfferDetails(lstItemSpecificCoupons); List <OfferDetail> updateOfferDetail = new List <OfferDetail>(); offerDetails.ItemSpecficOfferDetails?.ForEach(x => { if (x.Id > 0) { OfferDetail offerDetail = _couponManagmentRepository.GetOfferDetail(x.Id); offerDetail.ProductCode = x.ProductCode; offerDetail.Discount = x.Discount; offerDetail.FromDate = x.FromDate; offerDetail.ToDate = x.ToDate; offerDetail.DiscountType = x.DiscountType; updateOfferDetail.Add(offerDetail); } }); _couponManagmentRepository.SaveItemSpecificOfferDetails(updateOfferDetail); } else { Offer objOffer = new Offer(); SetOfferValuesBeforeSave(offerDetails, objOffer); List <OfferDetail> lstItemSpecificCoupons = new List <OfferDetail>(); OfferDetail objOfferDetail = new OfferDetail(); int OfferId = _couponManagmentRepository.SaveOfferDetails(objOffer); SetItemSpecificOfferDetails(offerDetails, objOfferDetail, OfferId, ref lstItemSpecificCoupons); _couponManagmentRepository.SaveItemSpecificOfferDetails(lstItemSpecificCoupons); } return(true); } catch (Exception) { throw; } }
public async Task <ApiError> CreateAsync(int userid, int beanid, long quantity, decimal price, DateTime expiration, bool buy) { var user = await _userRepository.ReadAsync(userid); if (user is null) { return(new(string.Format(Strings.NotFound, "user", "id", userid))); } var bean = await _beanRepository.ReadAsync(beanid); if (bean is null) { return(new(string.Format(Strings.NotFound, "bean", "id", beanid))); } if (quantity <= 0) { return(new(string.Format(Strings.Invalid, "quantity"))); } if (price <= 0M) { return(new(string.Format(Strings.Invalid, "price"))); } if (expiration <= DateTime.UtcNow) { return(new(string.Format(Strings.Invalid, "expiration date"))); } var offer = new OfferModel { Id = 0, UserId = userid, BeanId = beanid, Price = price, OfferDate = DateTime.UtcNow, ExpirationDate = expiration, Buy = buy, Quantity = quantity, Bean = null, User = null, CanDelete = true }; return(await InsertAsync(offer)); }
public ActionResult OfferCreatePos(OfferModel model) { if (Session["S_EmpID"] != null) { var resolveRequest = HttpContext.Request; resolveRequest.InputStream.Seek(0, SeekOrigin.Begin); string jsonString = new StreamReader(resolveRequest.InputStream).ReadToEnd(); List <OfferModel> sups = new List <OfferModel>(); if (jsonString != null) { if (Session["S_EmpID"].ToString() != null) { dynamic jArr2 = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString); foreach (dynamic item in jArr2) { foreach (var subitem in item.OfferModel) { model.SupID = subitem.SupID; model.EmpID = Session["S_EmpID"].ToString(); model.OffDate = System.DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); sups.Add(new OfferModel() { SupID = model.SupID, EmpID = model.EmpID, OffDate = model.OffDate }); } List <OfferDetailModel> myDeserializedObjList = item.OfferDetail.ToObject <List <OfferDetailModel> >(); var map_offer = Mapper._ToDto(sups); var map_offerDta = Mapper._ToDto(myDeserializedObjList); _offerRepository.InsertOffer(map_offer, map_offerDta); } return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); //return Json(_proRepository.ListProduct(), JsonRequestBehavior.AllowGet); //return View(_proRepository.ListProduct()); } return(RedirectToAction("Login2", "Account")); } return(View()); } else { return(RedirectToAction("Login2", "Account")); } }
private void SetItemSpecificOfferDetails(OfferModel offerDetails, OfferDetail objOfferDetail, int OfferId, ref List <OfferDetail> lstItemSpecificCoupons) { foreach (OfferdetailModel item in offerDetails.ItemSpecficOfferDetails) { objOfferDetail = new OfferDetail(); if (item.Id > 0) { objOfferDetail.Id = item.Id; } objOfferDetail.CreatedDate = offerDetails.CreatedDate; objOfferDetail.Discount = item.Discount; objOfferDetail.DiscountType = item.DiscountType; objOfferDetail.FromDate = item.FromDate; objOfferDetail.OfferCode = OfferId; objOfferDetail.ProductCode = item.ProductCode; objOfferDetail.ToDate = item.ToDate; lstItemSpecificCoupons.Add(objOfferDetail); } }
public async Task <ApiError> UpdateAsync(OfferModel model) { var checkresult = await ValidateModelAsync(model, true); if (!checkresult.Successful) { return(checkresult); } OfferEntity entity = model !; try { return(ApiError.FromDalResult(await _offerRepository.UpdateAsync(entity))); } catch (Exception ex) { return(ApiError.FromException(ex)); } }
public static OfferModel _ToDto(OfferModel entity) { if (entity == null) { return(null); } return(new OfferModel { OffID = entity.OffID, EmpID = entity.EmpID, EmpName = entity.EmpName, SupID = entity.SupID, SupName = entity.SupName, OffDate = entity.OffDate, OffStatus = entity.OffStatus, OffEnabled = entity.OffEnabled, EmpApprove = entity.EmpApprove, }); }
public IHttpActionResult Buy(int id, OfferModel offer) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var userName = this.User.Identity.Name; var client = this.data.Clients.All().Where(c => c.Account == userName).FirstOrDefault(); var existingOffer = this.data .Offers .All() .Where(a => a.Id == id && a.Deleted == false && a.BoughtBy == null) .FirstOrDefault(); if (existingOffer == null) { return(this.BadRequest("Such offer does not exists or it's already bought!")); } existingOffer.BoughtBy = client; existingOffer.BoughtDate = DateTime.Now; this.data.SaveChanges(); offer.Id = id; var newOffer = new { Id = client.Id, Quantity = offer.Quantity, ProductPhoto = offer.ProductPhoto, BoughtBy = offer.BoughtBy, PostDate = offer.PostDate, BoughtDate = offer.BoughtDate, ProductId = offer.ProductId , }; return(this.Ok(newOffer)); }
public ActionResult Create(OfferModel model) { try { if (ModelState.IsValid) { int GYM_ID = Convert.ToInt32(Session["GYM_ID"]); var Offer = Mapper.Map <Offer>(model); Offer.GYM_ID = GYM_ID; Offer.Status = true; db.Offers.Add(Offer); db.SaveChanges(); new Thread(new ThreadStart(() => { var Branches = db.Branches.Where(i => i.GYM_ID == GYM_ID).ToList(); foreach (var Branche in Branches) { Branch_Wise_Offer Branch_Wise_Offer = new Branch_Wise_Offer(); Branch_Wise_Offer.Branch_ID = Branche.ID; Branch_Wise_Offer.Status = true; Branch_Wise_Offer.GYM_ID = GYM_ID; Branch_Wise_Offer.Offer_ID = Offer.ID; db.Branch_Wise_Offer.Add(Branch_Wise_Offer); db.SaveChanges(); } })).Start(); TempData["Success"] = "Offer Has Created Successfully.!"; } else { TempData["Error"] = "Please Fill All Required Details.!"; return(View()); } return(RedirectToAction("Index", "Offer")); } catch (Exception ex) { return(RedirectToAction("Contact", "Home")); } }
public IHttpActionResult Add(OfferModel offer) { if (!this.ModelState.IsValid) { return(this.BadRequest("Invalid data")); } var isFarmer = this.User.IsInRole("Farmer"); if (!isFarmer) { return(this.BadRequest("You are not farmer!")); } var userName = this.User.Identity.Name; var product = this.data.Products.All() .FirstOrDefault(p => p.Id == offer.ProductId); var newOffer = new Offer { Quantity = offer.Quantity, ProductPhoto = offer.ProductPhoto, PostDate = DateTime.Now, ProductId = offer.ProductId, Product = product }; this.data.Offers.Add(newOffer); this.data.SaveChanges(); var returnOffer = new { Id = newOffer.Id, Quantity = newOffer.Quantity, ProductPhoto = newOffer.ProductPhoto, PostDate = newOffer.PostDate, ProductId = newOffer.ProductId, }; return(this.Ok(returnOffer)); }
private void btn_Save_Click(object sender, RoutedEventArgs e) { if (parentPage == (string)Application.Current.Resources["Coupons_leftHeader"]) { if (objValidations.CouponValidation(UCManageCoupon)) { CouponModel objSave = new CouponModel(rowId, UCManageCoupon.DiscountType, UCManageCoupon.FromDate, UCManageCoupon.ToDate, UCManageCoupon.NoOfCoupons, UCManageCoupon.Value, UserModelVm.CompanyId, UserModelVm.BranchId, UCManageCoupon.CouponName, true, false, UserModelVm.UserId, CommonFunctions.ParseDateToFinclaveString(DateTime.Now.Date.ToShortDateString())); if (_CouponManagmentControllers.SaveCouponDetails(objSave)) { SuccessRetrun(); } } } else { if (UCMangeOffer.TabControlOfferTypeSelectdIndex == (int)CommonEnum.ManageOfferTabControls.MinimumPurchaseAndDateTimeSpecific) { if (objValidations.OfferValidation(UCMangeOffer)) { OfferModel objSave = new OfferModel(rowId, UCMangeOffer.OfferType, UCMangeOffer.FromDate, UCMangeOffer.ToDate, UCMangeOffer.Discount, UCMangeOffer.MinimumValue, UserModelVm.CompanyId, UserModelVm.BranchId, UCMangeOffer.OfferName, true, false, UserModelVm.UserId, CommonFunctions.ParseDateToFinclaveString(DateTime.Now.Date.ToShortDateString())); bool isSaved = _CouponManagmentControllers.SaveOfferDetails(objSave); if (_CouponManagmentControllers.SaveOfferDetails(objSave)) { SuccessRetrun(); } } } else if (UCMangeOffer.TabControlOfferTypeSelectdIndex == (int)CommonEnum.ManageOfferTabControls.ItemSpecific) { List <OfferdetailModel> listOffer = UCMangeOffer.lvProducts.Items.Cast <OfferdetailModel>().Select(x => x).Select(y => new OfferdetailModel(y.Id, y.OfferId, y.ProductCode, y.Discount, y.FromDate, y.ToDate, Convert.ToString(Enum.Parse(typeof(CommonEnum.DiscountType), Convert.ToString(y.DiscountType))), y.ProductName)).ToList(); OfferModel offerDetails = new OfferModel(rowId, Convert.ToString((int)CommonEnum.OfferType.ItemSpecific), UserModelVm.CompanyId, UserModelVm.BranchId, UCMangeOffer.txtOfferName.Text, true, false, UserModelVm.UserId, CommonFunctions.ParseDateToFinclaveString(DateTime.Now.Date.ToShortDateString()), listOffer); if (_CouponManagmentControllers.SaveItemSpecificOfferDetails(offerDetails)) { SuccessRetrun(); } } } }
private List <DIBZ.Common.Model.Offer> CreateOfferForEachSelectedGameInReturn(List <int> offeredGameIds, int returnedGameId) { List <DIBZ.Common.Model.Offer> allOffers = new List <Common.Model.Offer>(); var offerLogic = LogicContext.Create <OfferLogic>(); foreach (var offeredGameId in offeredGameIds) { OfferModel offerRequest = new OfferModel(); offerRequest.ApplicationUserId = CurrentLoginSession.ApplicationUserId.GetValueOrDefault(); offerRequest.GameCatalogId = offeredGameId; offerRequest.AgaintsGameCatalogId = returnedGameId; var myExistingOffersCount = offerLogic.GetExistingOffers(CurrentLoginSession.ApplicationUserId.GetValueOrDefault(), offeredGameId, returnedGameId); if (myExistingOffersCount.Result.CompareTo(0) == 0) { allOffers.Add(offerLogic.AddUpdateOffer(offerRequest)); } } return(allOffers); }
public OfferModel PutChangeOffer(int id, [FromBody] OfferModel offer) { List <OfferModel> offers = GetDB(); OfferModel handle = offers.Find(x => x.Id == id); if (handle != null) { handle.OfferName = offer.OfferName; handle.OfferDescription = offer.OfferDescription; handle.OfferCreated = offer.OfferCreated; handle.OfferExpires = offer.OfferExpires; handle.RegularPrice = offer.RegularPrice; handle.ActionPrice = offer.ActionPrice; handle.ImagePath = offer.ImagePath; handle.AvailableOffers = offer.AvailableOffers; handle.BoughtOffers = offer.BoughtOffers; } return(handle); }
protected override async Task <bool> OnDelete(OfferModel offer) { bool ok; if (Offer.type == OfferType.Can) { ok = await CanService.DeleteCan(Offer.id); } else { ok = await WantService.DeleteWant(Offer.id); } if (ok) { SendOfferActionMessage(MessengerOfferActionType.Delete); } return(ok); }
private GetOfferResult ConvertOffer(Offer offer) { OfferModel offerModel = null; try { offerModel = string.IsNullOrWhiteSpace(offer.JData) ? null : JsonConvert.DeserializeObject <OfferModel>(offer.JData); } catch (Exception exc) { offerModel = new OfferModel(); } return(new GetOfferResult { Id = offer.Id, Type = offer.Type, State = offer.State, Offer = offerModel, UserId = offer.UserId, CreatedDate = offer.CreatedDate, UpdatedDate = offer.ChangedDate }); }
public ActionResult Create(OfferModel mydata) { if (Session["Customer_id"] != null) { if (Session["UserName"].ToString() == "ADMIN1" || Session["UserName"].ToString() == "ADMIN2") { if (ModelState.IsValid) { int result = Offer.Create(mydata); if (result != 0) { TempData["Package_Id"] = result; TempData["Campaign_ID"] = Offer.campaignId(Convert.ToInt32(TempData["Package_Id"])); return(RedirectToAction("Item")); } else { TempData["Message"] = "Wrong Date"; return(RedirectToAction("Create")); } } else { TempData["Message"] = "Wrong Data "; return(View()); } } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Login", "MyAccount")); } }
public IHttpActionResult PutOfferModel(int id, OfferModel offerModel) { // Mladen's model is very different from mine // He's using explicit foreign keys // In the OfferModel these are the CategoryID and SellerID properties // THIS IS PROBABLY AN IMPORTANT QUESTION TO ASK! // These concepts are called INDEPENDENT vs FOREIGN KEY ASSOCIATIONS // TODO follow up from here if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // in the User controller this id check is inside the service if (id != offerModel.id) { return(BadRequest()); } // Resenja se ovde razilaze // Kod mene nema provere da li pridruzena kategorija ili prodavac postoje // To ce dovesti do toga da ce sistem napraviti novu kategoriju // kao i novog prodavca // To ce se desiti i kada kategorija ili prodavac postoje // iz razloga jer ne postoji logika koja bi njih povezala sa postojecim entitetima // Kako u mom modelu nema CategoryId niti SellerId, logika bi bila ili u servisu ili // u kontroleru, ali znatno zamrsenija... // tipa: provera za kategoriju: // offerRepository.Get(filter: o => o.Name == ... && o.Description == ...) // ili pak, kroz Id, GetById((int)... kao i kod Mladena) // ali sa vaznom razlikom da tada moje resenje dodaje nove entitete // sto naravno, nije pozeljno! offerService.UpdateOffer(id, offerModel); return(StatusCode(HttpStatusCode.NoContent)); }
public virtual ActionResult Prices(int id, int offerId, OfferModel<OfferFormViewModel> formData) { var context = ModelFactory.GetUnitOfWork(); var oRepo = ModelFactory.GetRepository<IOfferRepository>(context); var lRepo = ModelFactory.GetRepository<ILocalisationRepository>(context); if (ModelState.IsValid) { try { var offer = oRepo.Get(formData.OfferModelId); TryUpdateModel(offer, "InnerModel.Offer"); context.Commit(); TempData[MiscHelpers.TempDataConstants.Info] = Worki.Resources.Views.Offer.OfferString.OfferEdited; return RedirectToAction(MVC.Backoffice.Offer.Prices(id, offer.Id)); } catch (Exception ex) { _Logger.Error("Prices", ex); context.Complete(); ModelState.AddModelError("", ex.Message); } } return View(formData); }
public virtual ActionResult Configure(int id, OfferModel<OfferFormViewModel> formData) { var memberId = WebHelper.GetIdentityId(User.Identity); var context = ModelFactory.GetUnitOfWork(); var oRepo = ModelFactory.GetRepository<IOfferRepository>(context); var mRepo = ModelFactory.GetRepository<IMemberRepository>(context); if (ModelState.IsValid) { try { var member = mRepo.Get(memberId); if (formData.InnerModel.Offer.AcceptBooking() && string.IsNullOrEmpty(member.MemberMainData.PaymentAddress)) { throw new Exception(Worki.Resources.Views.BackOffice.BackOfficeString.NeedInfoPaypal); } var o = oRepo.Get(formData.OfferModelId); TryUpdateModel(o, "InnerModel.Offer"); context.Commit(); TempData[MiscHelpers.TempDataConstants.Info] = Worki.Resources.Views.Offer.OfferString.OfferEdited; return RedirectToAction(MVC.Backoffice.Offer.Configure(o.LocalisationId, o.Id)); } catch (Exception ex) { _Logger.Error("Configure", ex); context.Complete(); ModelState.AddModelError("", ex.Message); } } return View(formData); }