Beispiel #1
0
        // GET: Auction/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var auction = await _context.auctions.FindAsync(id);

            if (auction == null)
            {
                return(NotFound());
            }

            EditAuctionModel editAuctionModel = new EditAuctionModel()
            {
                Id          = auction.Id,
                name        = auction.name,
                description = auction.description,
                base64Data  = Convert.ToBase64String(auction.image),
                startPrice  = auction.startPrice,
                openDate    = auction.openDate,
                closeDate   = auction.closeDate
            };

            return(View(editAuctionModel));
        }
        public async Task <IActionResult> EditAuction(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Auction auction = await this.context.Auctions.Include(a => a.owner).Where(a => a.Id == id).FirstOrDefaultAsync();

            User loggedInUser = await this.userManager.GetUserAsync(base.User);

            if (auction == null || (auction.owner.Id != loggedInUser.Id))
            {
                return(NotFound());
            }



            EditAuctionModel model = new EditAuctionModel()
            {
                id          = auction.Id,
                name        = auction.name,
                description = auction.description,
                startPrice  = auction.startPrice,
                openDate    = auction.openDate,
                openTime    = auction.openDate.ToString("HH:mm:ss"),
                closeDate   = auction.closeDate,
                closeTime   = auction.closeDate.ToString("HH:mm:ss"),
            };

            return(View(model));
        }
        public static EditAuctionModel getAuction(int id)
        {
            SqlConnection con  = new SqlConnection();
            string        path = ConfigurationManager.ConnectionStrings[db].ConnectionString;

            con.ConnectionString = path;
            DataTable        AuctionID = new DataTable();
            EditAuctionModel model     = new EditAuctionModel();

            try
            {
                SqlDataAdapter adpAuctions = new SqlDataAdapter("SELECT * from Auctions where AuctionID = '" + id + "'", con);
                adpAuctions.Fill(AuctionID);
            }
            catch (DataException e)
            {
                throw e;
            }

            foreach (DataRow row in AuctionID.Rows)
            {
                model.AuctionId  = Convert.ToInt32(row.ItemArray[0]);
                model.PropertyId = Convert.ToInt32(row.ItemArray[1]);
                model.StartTime  = Convert.ToDateTime(row.ItemArray[2]);
                model.EndTime    = Convert.ToDateTime(row.ItemArray[3]);;
            }
            return(model);
        }
        public async Task <IActionResult> EditAuction(int id)
        {
            User loggedInUser = await this.userManager.GetUserAsync(base.User);

            Auction auction = this.context.Auctions.FirstOrDefault(s => s.Id == id);

            int openH = auction.openDate.Hour;
            int openM = auction.openDate.Minute;

            int closeH = auction.closeDate.Hour;
            int closeM = auction.closeDate.Minute;

            if (auction != null && auction.owner == loggedInUser)
            {
                EditAuctionModel model = new EditAuctionModel()
                {
                    name        = auction.name,
                    description = auction.description,
                    startPrice  = Convert.ToString(auction.startPrice),
                    openDate    = auction.openDate,
                    closeDate   = auction.closeDate,
                    auctionId   = auction.Id,
                    openHour    = openH,
                    openMinute  = openM,
                    closeHour   = closeH,
                    closeMinute = closeM
                };



                return(View(model));
            }

            return(View());
        }
Beispiel #5
0
        public ActionResult Edit(int id, EditAuctionModel model)
        {
            try
            {
                // TODO: Add update logic here
                DataController.editAuction(id, model);



                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static void editAuction(int id, EditAuctionModel model)
        {
            SqlConnection con  = new SqlConnection();
            string        path = ConfigurationManager.ConnectionStrings[db].ConnectionString;

            con.ConnectionString = path;

            try
            {
                SqlCommand Cmd = new SqlCommand("UPDATE Auctions SET PropertyID = '" + model.PropertyId + "', StartTime = '" + model.StartTime + "', endTime = '" + model.EndTime + "' WHERE AuctionID = '" + id + "'", con);

                con.Open();
                int RowsAffected = Cmd.ExecuteNonQuery();

                // close connection when done
                con.Close();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #7
0
        // GET: Auction/Edit/5
        public ActionResult Edit(int id)
        {
            EditAuctionModel mod = DataController.getAuction(id);

            return(View(mod));
        }
        public async Task <IActionResult> EditAuction(EditAuctionModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string[] arr1 = model.openTime.Split(':', 3);
            string[] arr2 = model.closeTime.Split(':', 3);

            TimeSpan ts1 = new TimeSpan(Convert.ToInt32(arr1[0]), Convert.ToInt32(arr1[1]), Convert.ToInt32(arr1[2]));
            TimeSpan ts2 = new TimeSpan(Convert.ToInt32(arr2[0]), Convert.ToInt32(arr2[1]), Convert.ToInt32(arr2[2]));

            model.openDate  = model.openDate.Date + ts1;
            model.closeDate = model.closeDate.Date + ts2;

            if (DateTime.Compare(DateTime.Now, model.openDate) > 0)
            {
                ModelState.AddModelError("", "Invalid open date! (minimal time is +5minuts form now)");
                return(View(model));
            }
            else if (DateTime.Compare(model.openDate, model.closeDate) > 0)
            {
                ModelState.AddModelError("", "Close date must be greater than open date!");
                return(View(model));
            }

            Auction auction = await this.context.Auctions.Where(a => a.Id == model.id).FirstOrDefaultAsync();

            auction.name         = model.name;
            auction.description  = model.description;
            auction.startPrice   = model.startPrice;
            auction.currentPrice = model.startPrice;
            auction.createDate   = DateTime.Now;
            auction.openDate     = model.openDate;
            auction.closeDate    = model.closeDate;


            if (model.file == null)
            {
                try
                {
                    this.context.Update(auction);
                    await this.context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            else
            {
                using (BinaryReader reader = new BinaryReader(model.file.OpenReadStream( ))) {
                    auction.image = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length));

                    try
                    {
                        this.context.Update(auction);
                        await this.context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                    }
                }
            }



            return(RedirectToAction(nameof(AuctionController.Index), "Auction"));
        }
Beispiel #9
0
        public async Task <IActionResult> Edit(int id, EditAuctionModel auctionModel)
        {
            var auction = await _context.auctions.FindAsync(id);


            if (id != auction.Id)
            {
                return(NotFound());
            }

            if (auction.state != Auction.AuctionState.DRAFT)
            {
                auctionModel.base64Data = Convert.ToBase64String(auction.image);
                ModelState.AddModelError("", "This auction can not be edited.");
                ModelState.AddModelError("", "Sorry!");
                return(View(auctionModel));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    auction.name         = auctionModel.name;
                    auction.description  = auctionModel.description;
                    auction.startPrice   = auctionModel.startPrice;
                    auction.currentPrice = auctionModel.startPrice;
                    auction.openDate     = auctionModel.openDate;
                    auction.closeDate    = auctionModel.closeDate;

                    if (auctionModel.image != null)
                    {
                        using (BinaryReader reader = new BinaryReader(auctionModel.image.OpenReadStream( ))) {
                            auction.image = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length));
                        };
                    }

                    _context.Update(auction);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuctionExists(auction.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                if (User.FindFirst(ClaimTypes.Role).Value == "Admin")
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction(nameof(MyAuctions), "Auction"));
                }
            }

            return(View(auctionModel));
        }
        public async Task <IActionResult> EditAuction(EditAuctionModel model)
        {
            //User loggedInUser = await this.userManager.GetUserAsync(base.User);

            Auction auction = this.context.Auctions.FirstOrDefault(s => s.Id == model.auctionId);

            if (auction.name != model.name)
            {
                auction.name = model.name;
            }

            if (auction.description != model.description)
            {
                auction.description = model.description;
            }

            if (auction.startPrice != Convert.ToInt32(model.startPrice))
            {
                if (!Microsoft.VisualBasic.Information.IsNumeric(model.startPrice))
                {
                    ModelState.AddModelError("", "Start price not valid!");
                    return(View(model));
                }
                auction.startPrice   = Convert.ToInt32(model.startPrice);
                auction.currentPrice = Convert.ToInt32(model.startPrice);
            }

            if (model.openHour > 0)
            {
                model.openDate = model.openDate.AddHours(Convert.ToDouble(model.openHour));
            }

            if (model.openMinute > 0)
            {
                model.openDate = model.openDate.AddMinutes(Convert.ToDouble(model.openMinute));
            }

            if (model.closeHour > 0)
            {
                model.closeDate = model.closeDate.AddHours(model.closeHour);
            }

            if (model.closeMinute > 0)
            {
                model.closeDate = model.closeDate.AddMinutes(model.closeMinute);
            }

            if (model.openDate < DateTime.Now)
            {
                ModelState.AddModelError("", "Open date not valid!");
            }

            if (model.openDate >= model.closeDate)
            {
                ModelState.AddModelError("", "Open date and close date not valid!");
            }

            auction.openDate  = model.openDate;
            auction.closeDate = model.closeDate;


            if (model.image != null)
            {
                using (BinaryReader reader = new BinaryReader(model.image.OpenReadStream( ))) {
                    auction.image = reader.ReadBytes(Convert.ToInt32(reader.BaseStream.Length));
                };
            }

            await this.context.SaveChangesAsync( );

            //await signInManager.RefreshSignInAsync(loggedInUser);

            return(RedirectToAction(nameof(UserController.EditAuctionList), "User"));
        }