Exemple #1
0
        public ActionResult Index(DealModels newDeal)
        {
            if (ModelState.IsValid)
            {
                newDeal.City = dbHelper.GetCityByUrlName(newDeal.City.Name);
                newDeal.City.CityId = dbHelper.GetCityByUrlName(newDeal.City.UrlName).CityId;

                // user not specified start and end date
                if (newDeal.StartDate.Year == 1 || newDeal.EndDate.Year == 1)
                {
                    newDeal.StartDate = DateTime.Now;
                    newDeal.EndDate = DateTime.Now + new TimeSpan(5,0,0);
                }

                // image is from harddrive
                if (newDeal.PhotoUrl == null)
                {
                    newDeal.PhotoUrl = "../../uploads/defaultPhoto.png";
                }
                else if(!newDeal.PhotoUrl.StartsWith("http://"))
                {
                    newDeal.PhotoUrl = "../../uploads/" + newDeal.PhotoUrl;
                }

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    newDeal.User = dbHelper.GetUser(HttpContext.User.Identity.Name);
                }

                dbHelper.AddDealsToValidated(newDeal);
            }
            return View("_DodanoOferte");
        }
Exemple #2
0
        public bool AddDealsToValidated(DealModels deal)
        {
            try
            {
                var nDeal = ConvertNotValidatedDeal(deal);
                dbStore.NotValidatedDeal.Add(nDeal);
                dbStore.SaveChange();
                return true;
            }
            catch (Exception e)
            {
                throw e;
            }

            return false;
        }
Exemple #3
0
        public bool AddDealsToMainList(DealModels deal)
        {
            try
            {
                deal.AddedDate = DateTime.Now;
                dbStore.Entry(deal).State = EntityState.Modified;
                dbStore.Deal.Add(deal);
                dbStore.SaveChanges();
                dbStore = new RazemTaniejEntities();
                return true;
            }
            catch (Exception e)
            {
                throw e;
            }

            return false;
        }
Exemple #4
0
        private DealModels CopyDeal(DealModels deal)
        {
            var copy = new DealModels
            {
                AddedDate = deal.AddedDate,
                Category = deal.Category,
                City = deal.City,
                Comments = deal.Comments,
                CommercialNetworks = deal.CommercialNetworks,
                Description = deal.Description,
                EndDate = deal.EndDate,
                Expired = deal.Expired,
                Forum = deal.Forum,
                NumberOfComments = deal.NumberOfComments,
                PhotoUrl = deal.PhotoUrl,
                Prize = deal.Prize,
                Quality = deal.Quality,
                Rank = deal.Rank,
                StartDate = deal.StartDate,
                Title = deal.Title,
                UrlDeal = deal.UrlDeal,
                User = deal.User
            };

            return copy;
        }
Exemple #5
0
        /// <summary>
        /// Testuje daty
        /// </summary>
        /// <param name="deals"></param>
        /// <returns></returns>
        public bool Test1_A(IEnumerable<DealModels> deals)
        {
            var query = dbHelper.GetDealsBasicView(deals);

            DealModels oldItem = new DealModels { StartDate = new DateTime(2055,10,10,10,10,10) };
            foreach (var item in query)
            {
                if (item.StartDate.Ticks < oldItem.StartDate.Ticks)
                {
                    oldItem = item;
                }
                else
                {
                    return false;
                }

            }

            return true;
        }
Exemple #6
0
 public void IncrementDealComments(DealModels deal)
 {
     deal.NumberOfComments = deal.NumberOfComments + 1;
 }
Exemple #7
0
 public bool EditDeal(DealModels deal)
 {
     try
     {
        dbStore.Deal.Add(deal);
        RemoveValidatedDeal(deal.DealId);
        dbStore.SaveChanges();
     }
     catch (Exception e)
     {
         //TODO ?
         return false;
     }
     return true;
 }
Exemple #8
0
        public DealModels ConvertNotValidatedDeal(NotValidatedDealModels deal)
        {
            var newDeal = new DealModels
            {
                AddedDate = DateTime.Now,
                Category = deal.Category,
                City = deal.City,
                Comments = deal.Comments,
                CommercialNetworks = deal.CommercialNetworks,
                Description = deal.Description,
                EndDate = deal.EndDate,
                Expired = deal.Expired,
                Forum = deal.Forum,
                NumberOfComments = deal.NumberOfComments,
                PhotoUrl = deal.PhotoUrl,
                Prize = deal.Prize,
                Quality = deal.Quality,
                StartDate = deal.StartDate,
                Title = deal.Title,
                UrlDeal = deal.UrlDeal,
                User = deal.User,
                Rank = deal.Rank
            };

            return newDeal;
        }
Exemple #9
0
        public bool CheckIfUserRankedDealBefore(DealModels deal, UserModels user)
        {
            var query = from p in user.RankedDeals
                        where p == deal
                        select p;

            if (query.Count() == 0)
            {
                return false;
            }

            return true;
        }
Exemple #10
0
 public void AddPositiveMark(DealModels deal, UserModels user)
 {
     deal.Rank = deal.Rank + 1;
     user.RankedDeals.Add(deal);
     dbStore.SaveChanges();
 }
Exemple #11
0
 public ActionResult Index()
 {
     var newDeal = new DealModels();
     ToolUtils._lastUrl = "../DodajOferte";
     return View(newDeal);
 }
 public ActionResult ValidatedItem(DealModels deal)
 {
     dbHelper.EditDeal(deal);
     return RedirectToAction("Index", "Administrator");
 }
 public ActionResult Index(DealModels deal)
 {
     dbHelper.AddDealsToValidated(deal);
     return RedirectToAction("Index", "Administrator");
 }