Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
 // 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());
 }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        public ActionResult Category(int id)
        {
            ViewBag.Categories = CategoryModel.GetCategoryById(null);
            ViewBag.Category   = CategoryModel.GetCategoryById(id).First();
            var lots = LotModel.GetLotByCategoryId(id);

            return(View(lots));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
        public ActionResult Ended()
        {
            ViewBag.Categories = CategoryModel.GetCategoryById(null);

            var lots = LotModel.GetEndedLots();

            return(View(lots));
        }
Exemplo n.º 14
0
        public ActionResult CreateLot()
        {
            ViewBag.Categories = CategoryModel.GetCategoryById(null);
            ViewBag.Partners   = Partner.GetPartner(null, null);
            var lot = new LotModel();

            return(View(lot));
        }
Exemplo n.º 15
0
        public ActionResult Search(string query)
        {
            ViewBag.Categories = CategoryModel.GetCategoryById(null);

            ViewBag.Query = query;
            var lots = LotModel.GetLotByQuery(query);

            return(View(lots));
        }
Exemplo n.º 16
0
        public ActionResult PartnerItems(int id)
        {
            var partner = Partner.GetPartner(id, null).First();

            ViewBag.Partner = partner;
            var lots = LotModel.GetLotByPartnerId(id);

            return(View(lots));
        }
Exemplo n.º 17
0
 public ActionResult DeleteLot(LotModel Model)
 {
     if (Auction.DeleteLot(Model))
     {
         return(RedirectToAction("Index", "Home"));
     }
     ModelState.AddModelError("", "Fail while model deleting.");
     return(Index(Model));
 }
Exemplo n.º 18
0
        public ActionResult CreateLot()
        {
            var model      = new LotModel();
            var categories = GetCategories();

            model.Categories = GetSelectListItems(categories);

            return(View(model));
        }
Exemplo n.º 19
0
        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)));
        }
Exemplo n.º 20
0
        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;
                    }
                }
            }
        }
Exemplo n.º 21
0
        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)));
        }
Exemplo n.º 22
0
        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)));
        }
Exemplo n.º 23
0
        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)));
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 26
0
        public static DbContext GetCurrentDbContext()
        {
            DbContext context = CallContext.GetData("DbContext") as DbContext;

            if (context == null)
            {
                context = new LotModel();
                CallContext.SetData("DbContext", context);
            }
            return(context);
        }
Exemplo n.º 27
0
 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);
     }
 }
Exemplo n.º 28
0
        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));
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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;
                    }
                }
            }
        }