예제 #1
0
        public ActionResult Create(string companyAdmin = null)
        {
            // var jest=Roles.IsUserInRole(User.Identity.Name, "Admin");
            if (!Roles.IsUserInRole(User.Identity.Name, "Admin"))
                return View("InvalidOwner");
            if (!CanAddAuction())
                return View("OverLimit");

            if (companyAdmin == null)
                companyAdmin = User.Identity.Name;

            int? companyId=InBidEntities.aspnet_Users.Where(x=>x.UserName==companyAdmin).FirstOrDefault().CompanyId;

            PopulateRelatedAuctionsDropDownLists(companyId);

            ViewData["Currency"] = setCurrency();
            ViewData["Direction"] = "True";
            ViewData["ViewTopOffer"] = "True";
            ViewData["EnableDisable"] = "True";

            Auction auction = new Auction()
            {
                MinJump=0,
                StartTime=DateTime.Now,
                //EndTime = DateTime.Now.AddDays(2)
                Days=30,
                Hours=0,
                Minutes=0,
                Seconds=0

                //EventDate = DateTime.Now.AddDays(7)
            };

            //changeDateIn1Auction(auction);

            return View(auction);
        }
예제 #2
0
        public ActionResult Create(Auction auction,int IsAfterAuction=0, string companyAdmin=null )
        {
            if (!Roles.IsUserInRole(User.Identity.Name, "Admin"))
                return View("InvalidOwner");
            if (!CanAddAuction())
                return View("OverLimit");

            int? companyId;

            if (ModelState.IsValid)
            {
                Guid currentUserId;
                if (Roles.IsUserInRole(User.Identity.Name, "SuperAdmin"))
                {
                    currentUserId = InBidEntities.aspnet_Users.Where(x => x.UserName == companyAdmin).FirstOrDefault().UserId;
                }
                else
                {
                    MembershipUser mu = Membership.GetUser();
                     currentUserId = (Guid)mu.ProviderUserKey;
                }
                auction.UserId = currentUserId;

                if (companyAdmin == null)
                    companyAdmin = User.Identity.Name;

                companyId = InBidEntities.aspnet_Users.Where(x => x.UserName == companyAdmin).FirstOrDefault().CompanyId;
                var companyAuctionsCounter = InBidEntities.vw_CompanyAuctions.Where(x => x.CompanyId == companyId).Count();

                //InbidIdentity nerd = (InbidIdentity)User.Identity;
            //                auction.StartTime=auction.StartTime.ToUniversalTime();
                //auction.EndTime = auction.EndTime.ToUniversalTime();
                auction.CurrentPrice = auction.StartPrice;
                //auction.EnableDisable = true;
                auction.AuctionNumber = companyId.ToString() + "-" + (companyAuctionsCounter + 1).ToString();

                auction.DateAdd = System.DateTime.UtcNow;
                auction.DateEdit = System.DateTime.UtcNow;

                if (IsAfterAuction == -1)
                {
                    if (auction.RelatedAuction == null)
                    {
                        ModelState.AddModelError("", "Nie wybrałeś powiązanej aukcji");

                        companyId = InBidEntities.aspnet_Users.Where(x => x.UserId == currentUserId).FirstOrDefault().CompanyId;
                        PopulateRelatedAuctionsDropDownLists(companyId);

                        return View(auction);
                    }
                    System.TimeSpan timeInterval = new TimeSpan(auction.IntervalDays, auction.IntervalHours, auction.IntervalMinutes, auction.IntervalSeconds);
                    auction.TimeInterval = timeInterval.Ticks;
                    var relatedAuctionEndTime = InBidEntities.Auctions.Where(x => x.AuctionId == auction.RelatedAuction).FirstOrDefault().EndTime;
                    auction.StartTime = relatedAuctionEndTime + timeInterval;

                    System.TimeSpan ts = new TimeSpan(auction.Days, auction.Hours, auction.Minutes, auction.Seconds);
                    auction.EndTime = auction.StartTime + ts;

                }
                else
                {

                    auction.StartTime = auction.StartTime.ToUniversalTime();
                    System.TimeSpan ts = new TimeSpan(auction.Days, auction.Hours, auction.Minutes, auction.Seconds);
                    auction.EndTime = auction.StartTime + ts;
                    auction.RelatedAuction = null;
                }

                InBidEntities.AddToAuctions(auction);

                InBidEntities.SaveChanges();

                return RedirectToAction("Index");
            }

            if (companyAdmin == null)
                companyAdmin = User.Identity.Name;

            companyId = InBidEntities.aspnet_Users.Where(x => x.UserName == companyAdmin).FirstOrDefault().CompanyId;

            PopulateRelatedAuctionsDropDownLists(companyId,auction.RelatedAuction);

            return View(auction);
        }
예제 #3
0
 //public AuctionController()
 // {
 //     InBidEntities=new InBidEntities();
 // }
 //protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 // {
 //     base.Initialize(requestContext);
 // }
 void changeDateIn1Auction(Auction a)
 {
     a.StartTime += System.TimeSpan.FromHours(System.Double.Parse(Request.Cookies["TimeZone"].Value));
        a.EndTime += System.TimeSpan.FromHours(System.Double.Parse(Request.Cookies["TimeZone"].Value));
 }
예제 #4
0
        public ActionResult Edit(int id, Auction auction, int IsAfterAuction = 0)
        {
            Auction a = InBidEntities.Auctions.Where(x => x.AuctionId == id).SingleOrDefault();

            Guid currentUserId;

            if (Roles.IsUserInRole(User.Identity.Name, "SuperAdmin"))
            {
                currentUserId = InBidEntities.aspnet_Users.Where(x => x.UserId == a.UserId).FirstOrDefault().UserId;
            }
            else
            {
                MembershipUser mu = Membership.GetUser();
                currentUserId = (Guid)mu.ProviderUserKey;
            }
            int? companyId = InBidEntities.aspnet_Users.Where(x => x.UserId == currentUserId).FirstOrDefault().CompanyId;

                if (ModelState.IsValid)
                {
                    //if (!Roles.IsUserInRole(User.Identity.Name, "SuperAdmin"))
                    //{
                    //    if (!auction.IsHostedBy())
                    //        return View("InvalidOwner");
                    //}

                    a.Name = auction.Name;
                    a.MinJump = auction.MinJump;
                    a.Currency = auction.Currency;
                    a.Description = auction.Description;
                    a.EnableDisable = auction.EnableDisable;
                    a.ViewTopOffer = auction.ViewTopOffer;
                    a.DateEdit = System.DateTime.UtcNow;

                    if (IsAfterAuction == -1)
                    {
                        if (auction.RelatedAuction == null)
                        {
                            ModelState.AddModelError("", "Nie wybrałeś powiązanej aukcji");

                             companyId = InBidEntities.aspnet_Users.Where(x => x.UserId == currentUserId).FirstOrDefault().CompanyId;
                            PopulateRelatedAuctionsDropDownLists(companyId);

                            return View(auction);
                        }
                        System.TimeSpan timeInterval = new TimeSpan(auction.IntervalDays, auction.IntervalHours, auction.IntervalMinutes, auction.IntervalSeconds);
                        auction.TimeInterval = timeInterval.Ticks;
                        var relatedAuctionEndTime = InBidEntities.Auctions.Where(x => x.AuctionId == auction.RelatedAuction).FirstOrDefault().EndTime;
                        auction.StartTime = relatedAuctionEndTime + timeInterval;

                        System.TimeSpan ts = new TimeSpan(auction.Days, auction.Hours, auction.Minutes, auction.Seconds);
                        auction.EndTime = auction.StartTime + ts;

                    }
                    else
                    {

                        auction.StartTime = auction.StartTime.ToUniversalTime();
                        System.TimeSpan ts = new TimeSpan(auction.Days, auction.Hours, auction.Minutes, auction.Seconds);
                        auction.EndTime = auction.StartTime + ts;
                        auction.RelatedAuction = null;
                    }

                    InBidEntities.SaveChanges();

                    return RedirectToAction("Index");
                }

                PopulateRelatedAuctionsDropDownLists(companyId,auction.RelatedAuction);

            return View(auction);
        }
예제 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Auctions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAuctions(Auction auction)
 {
     base.AddObject("Auctions", auction);
 }
예제 #6
0
 /// <summary>
 /// Create a new Auction object.
 /// </summary>
 /// <param name="auctionId">Initial value of the AuctionId property.</param>
 /// <param name="startPrice">Initial value of the StartPrice property.</param>
 /// <param name="currentPrice">Initial value of the CurrentPrice property.</param>
 /// <param name="direction">Initial value of the Direction property.</param>
 /// <param name="currency">Initial value of the Currency property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="startTime">Initial value of the StartTime property.</param>
 /// <param name="endTime">Initial value of the EndTime property.</param>
 /// <param name="enableDisable">Initial value of the EnableDisable property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="minJump">Initial value of the MinJump property.</param>
 public static Auction CreateAuction(global::System.Int32 auctionId, global::System.Decimal startPrice, global::System.Decimal currentPrice, global::System.Boolean direction, global::System.String currency, global::System.String name, global::System.DateTime startTime, global::System.DateTime endTime, global::System.Boolean enableDisable, global::System.Guid userId, global::System.Decimal minJump)
 {
     Auction auction = new Auction();
     auction.AuctionId = auctionId;
     auction.StartPrice = startPrice;
     auction.CurrentPrice = currentPrice;
     auction.Direction = direction;
     auction.Currency = currency;
     auction.Name = name;
     auction.StartTime = startTime;
     auction.EndTime = endTime;
     auction.EnableDisable = enableDisable;
     auction.UserId = userId;
     auction.MinJump = minJump;
     return auction;
 }