public ActionResult NewStorageLot(NewStorageLotModel model) { if (ModelState.IsValid) { using (var db = new BGS_DBContext()) { string userIdentityId = User.Identity.GetUserId(); var seller = db.Users.Single(u => u.Id == userIdentityId); for (int i = 0; i < model.LotCount; i++) { StorageModel newStorageModel = GameUtilCreater.StorageModelFromModel(model); db.StorageModels.Add(newStorageModel); db.SaveChanges(); var lot = new LotModel() { Seller = seller, ItemId = newStorageModel.Id, Price = model.Price, SellerId = seller.GameId, Status = LotStatus.Available, Type = LotType.Storage }; db.LotModels.Add(lot); db.SaveChanges(); newStorageModel.LotId = lot.Id; } db.SaveChanges(); return(RedirectToAction("Index", "Market")); } } ModelState.AddModelError("", "Что то не правильно"); return(View(model)); }
// POST api/<controller> public async System.Threading.Tasks.Task <IHttpActionResult> PostLotAsync([FromBody] LotModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } value.SellerUserId = User.Identity.Name; try { await lotOperationsHandler.AddLotAsync(mapper.Map <Lot>(value), System.Web.Hosting.HostingEnvironment.MapPath(@"~"), Request.RequestUri.GetLeftPart(UriPartial.Authority)); } catch (WrongIdException ex) { return(Content(HttpStatusCode.NotFound, ex.Message)); } catch (WrongModelException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(InternalServerError(ex)); } return(Ok()); }
public JsonResult CreateBid(BidModel bid) { try { LotModel lot = LotModel.GetLotById(bid.LotId).First(); if (lot.DeadLine < DateTime.Now) { return(Json("@Resource.LotDayPassed", JsonRequestBehavior.AllowGet)); } if (bid.Amount < lot.CurrentBid + lot.Step) { return(Json("Amount is low than the current bid's", JsonRequestBehavior.AllowGet)); } else { bid.UserId = User.Identity.GetUserId(); bid.Save(); return(Json("Bid made successfully. ", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { throw ex; } }
private async void SubDLotSaveLot(object sender, RoutedEventArgs e) { try { var subDLotEntry = new LotModel() { AddressPermitNum = SubDLotAddress.Text, LotNum = int.Parse(SubDLotNum.Text), PlanPhase = SubDLotPhaseNum.Text, Phase = SubDLotPlanStatus.Text, SubDivisionID = int.Parse(TestingPage.TempSelectedID) }; var lotJson = JsonConvert.SerializeObject(subDLotEntry); var client = new HttpClient(); var HttpContent = new StringContent(lotJson); HttpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); await client.PostAsync("http://localhost:62611/api/lots", HttpContent); AddSubDLotPopup.IsOpen = false; SubDLotAddress.Text = ""; SubDLotNum.Text = ""; SubDLotPhaseNum.Text = ""; SubDLotPlanStatus.Text = ""; } catch (Exception exception) { Console.WriteLine(exception); } }
public ActionResult Edit(LotModel model) { var categories = GetCategories(); model.Categories = GetSelectListItems(categories); model.CreatorId = HttpContext.User.Identity.GetUserId(); if (ModelState.IsValid) { Int32.TryParse(model.SelectedCategoryId, out int selectedId); LotDTO lotDTO = new LotDTO { Id = model.Id, Name = model.Name, Description = model.Description, StartPrice = model.StartPrice, BidRate = model.BidRate, CurrentPrice = model.StartPrice, CreatorId = model.CreatorId, Category = categoryService.GetCategory(selectedId), UserId = HttpContext.User.Identity.GetUserId(), }; lotService.Edit(lotDTO); return(RedirectToAction("UserLotsListing")); } return(View("Edit", model)); }
public async Task <ActionResult> Edit(LotModel model) { if ((!User.IsInRole("Admin") && User.Identity.GetUserId() != model.SellerId) || !string.IsNullOrWhiteSpace(model.BuyerId)) { return(RedirectToAction("Forbidden", "Errors")); } if (ModelState.IsValid) { var result = await _lotService.UpdateAsync(model); if (result.Succedeed) { return(RedirectToAction("Details", new { id = ((LotModel)result.ReturnValue).Id })); } foreach (var error in result.ValidationResults) { ModelState.AddModelError(error.MemberNames.First(), error.ErrorMessage); } } return(View(model)); }
public async Task <LotModel> AddLot(LotModel lot) { if (lot == null) { throw new ArgumentNullException(nameof(lot)); } using (var db = new AuctionContext()) { var lotEntity = new Lot { Id = lot.Id, Name = lot.Name, Description = lot.Description, Quantity = lot.Quantity, Unit = lot.Unit, StartingPrice = lot.StartingPrice, CurrentPrice = lot.CurrentPrice, MinimalBid = lot.MinimalBid, BidCount = lot.BidCount, AuctionDate = lot.AuctionDate }; db.Lots.Add(lotEntity); await db.SaveChangesAsync(); lot.Id = lotEntity.Id; return(lot); } }
public ActionResult Index() { var top = LotModel.GetTopLots(1); ViewBag.Top = top; var secondTop = LotModel.GetTopLots(2); ViewBag.SecondTop = secondTop; var thirdTop = LotModel.GetTopLots(3); ViewBag.ThirdTop = thirdTop; var lots = LotModel.GetLotById(null); try{ lots.RemoveAll(l => l.Id == top.Id); lots.RemoveAll(l => l.Id == secondTop.Id); lots.RemoveAll(l => l.Id == thirdTop.Id); } catch { } ViewBag.Categories = CategoryModel.GetCategoryById(null); if (Request.IsAuthenticated) { ViewBag.WinnedBids = BidModel.GetWinnerBids(User.Identity.GetUserId()); } return(View(lots)); }
public async Task <LotModel> EditLot(LotModel lot) { if (lot == null) { throw new ArgumentNullException(nameof(lot)); } using (var db = new AuctionContext()) { var lotEntity = db.Lots.FirstOrDefault(L => L.Id == lot.Id); if (lotEntity == null) { return(null); } lotEntity.Name = lot.Name; lotEntity.Description = lot.Description; lotEntity.Quantity = lot.Quantity; lotEntity.Unit = lot.Unit; lotEntity.StartingPrice = lot.StartingPrice; lotEntity.CurrentPrice = lot.CurrentPrice; lotEntity.MinimalBid = lot.MinimalBid; lotEntity.BidCount = lot.BidCount; lotEntity.AuctionDate = lot.AuctionDate; await db.SaveChangesAsync(); return(lot); } }
public ActionResult Category(int id) { ViewBag.Categories = CategoryModel.GetCategoryById(null); ViewBag.Category = CategoryModel.GetCategoryById(id).First(); var lots = LotModel.GetLotByCategoryId(id); return(View(lots)); }
public ActionResult EditLot(int id) { LotModel lot = LotModel.GetLotById(id).First(); ViewBag.Partners = Partner.GetPartner(null, null); ViewBag.Categories = CategoryModel.GetCategoryById(null); return(View("CreateLot", lot)); }
public static void MakeBet(LotModel model, string username) { if (model.LeaderName != null && username != model.LeaderName) { EmailSender.ToLeaderOnChangedRate(model, username); } dataAccess.MakeBet(model.ID, username, model.Currency); }
public ActionResult Ended() { ViewBag.Categories = CategoryModel.GetCategoryById(null); var lots = LotModel.GetEndedLots(); return(View(lots)); }
public ActionResult CreateLot() { ViewBag.Categories = CategoryModel.GetCategoryById(null); ViewBag.Partners = Partner.GetPartner(null, null); var lot = new LotModel(); return(View(lot)); }
public ActionResult Search(string query) { ViewBag.Categories = CategoryModel.GetCategoryById(null); ViewBag.Query = query; var lots = LotModel.GetLotByQuery(query); return(View(lots)); }
public ActionResult PartnerItems(int id) { var partner = Partner.GetPartner(id, null).First(); ViewBag.Partner = partner; var lots = LotModel.GetLotByPartnerId(id); return(View(lots)); }
public ActionResult DeleteLot(LotModel Model) { if (Auction.DeleteLot(Model)) { return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "Fail while model deleting."); return(Index(Model)); }
public ActionResult CreateLot() { var model = new LotModel(); var categories = GetCategories(); model.Categories = GetSelectListItems(categories); return(View(model)); }
public static bool ToOwnerOnComplete(LotModel model) { var membershipUser = Membership.GetUser(model.OwnerName); return(membershipUser != null && SendEamil(membershipUser.Email, model.Name, String.Format( "Hello, {0} \r\n Sorry, but your lot {1}, was removed from the auction. \r\n ", model.OwnerName, model.Name))); }
internal List <LotModel> getLotByPartnerId(int id) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("sp_GetLotsByParent", sqlConnection)) { try { sqlConnection.Open(); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Id", id); string culture = Thread.CurrentThread.CurrentCulture.Parent.Name.ToUpper(); SqlDataReader rdr = command.ExecuteReader(); List <LotModel> lotList = new List <LotModel>(); while (rdr.Read()) { LotModel lot = new LotModel(); lot.Id = Convert.ToInt32(rdr["Id"]); lot.ImageSource = rdr["ImageSource"].ToString(); lot.Name = rdr["Name_" + culture].ToString(); lot.Name_AM = rdr["Name_AM"].ToString(); lot.Name_EN = rdr["Name_EN"].ToString(); lot.Info = rdr["Info_" + culture].ToString(); lot.Info_AM = rdr["Info_AM"].ToString(); lot.Info_EN = rdr["Info_EN"].ToString(); lot.Description = rdr["Description_" + culture].ToString(); lot.Description_AM = rdr["Description_AM"].ToString(); lot.Description_EN = rdr["Description_EN"].ToString(); lot.Policy = rdr["Policy_" + culture].ToString(); lot.Policy_AM = rdr["Policy_AM"].ToString(); lot.Policy_EN = rdr["Policy_EN"].ToString(); lot.CurrentBid = Convert.ToDecimal(rdr["CurrentBid"].ToString()); lot.Step = Convert.ToDecimal(rdr["Step"].ToString()); lot.EstimatedValue = Convert.ToDecimal(rdr["EstimatedValue"].ToString()); lot.CategoryId = Convert.ToInt32(rdr["CategoryId"]); lot.CreateDate = Convert.ToDateTime(rdr["CreateDate"]); lot.DeadLine = Convert.ToDateTime(rdr["DeadLine"]); lot.OccureDate = Convert.ToDateTime(rdr["OccureDate"]); lot.PartnerId = Convert.ToInt32(rdr["PartnerId"]); lot.isShownCelebrity = Convert.ToBoolean(rdr["isShownCelebrity"]); lotList.Add(lot); } return(lotList); } catch (Exception ex) { throw ex; } } } }
public static bool ToLeaderOnChangedRate(LotModel model, string newLeader) { var membershipUser = Membership.GetUser(model.LeaderName); return(membershipUser != null && SendEamil(membershipUser.Email, model.Name, String.Format( "Hello, {0} \r\n Your bid on lot <a href=\"{1}/Lot/Index/{2}\"> {3} </a>, was broken by <a href=\"{1}/localhost/OnlineAuction/Account/Profile?name={4}\"> {4} </a>", model.LeaderName, LOCAL, model.ID, model.Name, newLeader))); }
public static bool ToLeaderOnComplete(LotModel model) { var membershipUser = Membership.GetUser(model.LeaderName); return(membershipUser != null && SendEamil(membershipUser.Email, model.Name, String.Format( "Hello, {0} \r\n Congratulations? you won lot {1} by $ {2}! \r\n " + "Wait until you contact the seller", model.LeaderName, model.Name, model.Currency))); }
public static bool ToOwnerOnComplete(LotModel model, string leadername) { var membershipUser = Membership.GetUser(model.OwnerName); return(membershipUser != null && SendEamil(membershipUser.Email, model.Name, String.Format( "Hello, {0} \r\n Your lot {1}, was won by the user {2} by $ {4}. \r\n " + "Contact them for contacts listed in the user's profile:" + " {3}/OnlineAuction/Account/Profile?name={2}", model.OwnerName, model.Name, leadername, LOCAL, model.Currency))); }
private IList <MessageModel> GetAllMessages() { IList <MessageModel> list = new List <MessageModel>(); var connection = ConnetionToSqlServer.Default(); var select = $"exec dbo.GetMessageBetweenDates '{dtpStart.Value.ToString("yyyy-MM-dd")}', '{dtpEnd.Value.ToString("yyyy-MM-dd")}'"; //Log.Debug(select); var reader = connection.ExecuteReader(select); if (reader != null) { while (reader.Read()) { var desc = new MessageModel(); desc.Id = reader.GetGuid(0); desc.Number = reader.GetString(1); desc.DateStart = reader.GetDateTime(2); desc.DateEnd = reader.GetDateTime(3); desc.DateStartBargaining = reader.GetDateTime(4); desc.Url = reader.GetString(5); desc.Description = reader.GetString(6).Replace(";", ","); desc.DateMesage = reader.GetDateTime(7); desc.TypeOfBidding = reader.GetString(8); list.Add(desc); } reader.Close(); } foreach (var message in list) { select = $"exec dbo.GetLotByMessageID '{message.Id}'"; reader = connection.ExecuteReader(select); if (reader != null) { while (reader.Read()) { var lot = new LotModel() { Id = reader.GetGuid(0), Number = reader.GetInt32(1), Description = reader.GetString(2).Replace(";", ","), StartPrice = reader.GetDouble(3), Step = reader.GetString(4), Deposit = reader.GetString(5).Replace(";", ","), PriceReductionInformation = reader.GetString(6).Replace(";", ","), PropertyClassification = reader.GetString(7).Replace(";", ",") }; message.Lots.Add(lot); } reader.Close(); } } ; return(list); }
public ActionResult Index(LotModel model) { if (ModelState.IsValid) { Auction.MakeBet(model, HttpContext.User.Identity.Name); return(RedirectToAction("Index", "Lot", new { id = model.ID })); } var restoreModel = dataAccess.GetViewModelById(model.ID); return(View(restoreModel)); }
public static DbContext GetCurrentDbContext() { DbContext context = CallContext.GetData("DbContext") as DbContext; if (context == null) { context = new LotModel(); CallContext.SetData("DbContext", context); } return(context); }
public async Task <LotModel> AddLot(LotModel lot) { if (lots.Any(a => a.Id == lot.Id) || lots.Any(a => a.Name == lot.Name) || lots.Any(a => a.AuctionDate == lot.AuctionDate)) { return(null); } else { lots.Add(lot); return(lot); } }
public ActionResult Lots(int?id) { if (id == null) { id = CategoryModel.GetCategoryById(null).First().Id; } var lots = LotModel.AdminGetLotByCategoryId(Convert.ToInt32(id)); ViewBag.Categories = CategoryModel.GetCategoryById(null); return(View(lots)); }
public async Task <LotModel> CreateLot(LotModel filter) { Data.Contracts.Entities.Lot lot = _mapperAdapter.Map <Lot>(filter); Lot result = await _lotRepository.Add(lot); SentMessageToQueue(result.Id); var savedLot = _mapperAdapter.Map <LotModel>(result); return(savedLot); }
internal LotModel getTopLots(int index) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("sp_GetTopLots", sqlConnection)) { try { sqlConnection.Open(); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Index", index); string culture = Thread.CurrentThread.CurrentCulture.Parent.Name.ToUpper(); SqlDataReader rdr = command.ExecuteReader(); if (rdr.Read()) { LotModel lot = new LotModel(); lot.Id = Convert.ToInt32(rdr["Id"]); lot.ImageSource = rdr["ImageSource"].ToString(); lot.Name = rdr["Name_" + culture].ToString(); lot.Name_AM = rdr["Name_AM"].ToString(); lot.Name_EN = rdr["Name_EN"].ToString(); lot.Info = rdr["Info_" + culture].ToString(); lot.Info_AM = rdr["Info_AM"].ToString(); lot.Info_EN = rdr["Info_EN"].ToString(); lot.Description = rdr["Description_" + culture].ToString(); lot.Description_AM = rdr["Description_AM"].ToString(); lot.Description_EN = rdr["Description_EN"].ToString(); lot.Policy = rdr["Policy_" + culture].ToString(); lot.Policy_AM = rdr["Policy_AM"].ToString(); lot.Policy_EN = rdr["Policy_EN"].ToString(); lot.CurrentBid = Convert.ToDecimal(rdr["CurrentBid"].ToString()); lot.Step = Convert.ToDecimal(rdr["Step"].ToString()); lot.EstimatedValue = Convert.ToDecimal(rdr["EstimatedValue"].ToString()); lot.CategoryId = Convert.ToInt32(rdr["CategoryId"]); lot.CreateDate = Convert.ToDateTime(rdr["CreateDate"]); lot.DeadLine = Convert.ToDateTime(rdr["DeadLine"]); lot.OccureDate = Convert.ToDateTime(rdr["OccureDate"]); return(lot); } return(null); } catch (Exception ex) { throw ex; } } } }