Пример #1
0
 public ActionResult AddWishlist(int id)
 {
     Response.ContentType = "text/plaintext";
     if (User.Identity.GetUserId() != null)
     {
         string userId    = User.Identity.GetUserId();
         var    wishlists = db.Wishlists.Where(w => w.User.Id == userId && w.Product.Id == id).ToList <Wishlist>();
         //
         if (wishlists.Count() == 0)
         {
             Wishlist wishlist = db.Wishlists.Create();
             wishlist.Product      = db.Products.Find(id);
             wishlist.User         = db.Users.Find(userId);
             wishlist.title        = "#" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + wishlist.Product.Name;
             wishlist.created_date = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
             db.Wishlists.Add(wishlist);
             db.SaveChanges();
             Response.StatusCode = 202;
             return(Content(wishlist.Id.ToString()));
         }
         else
         {
             Wishlist wishlist = wishlists.First();
             Response.StatusCode = 204;
             return(Content(wishlist.Id.ToString()));
         }
     }
     else
     {
         Response.StatusCode = 403;
         return(Content(string.Empty));
     }
 }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("WishlistId,UserId,CoffeeId")] Wishlist wishlist)
        {
            if (id != wishlist.WishlistId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(wishlist);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WishlistExists(wishlist.WishlistId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CoffeeId"] = new SelectList(_context.Coffee, "CoffeeId", "Description", wishlist.CoffeeId);
            ViewData["UserId"]   = new SelectList(_context.ApplicationUsers, "Id", "Id", wishlist.UserId);
            return(View(wishlist));
        }
Пример #3
0
        public void removeCourseFromStudentWishlist_HappyPath_NoPriorityChange()
        {
            //Get Last Entry
            int             studentNum      = 1;
            List <Wishlist> wishlistEntries = _context.Wishlist.Where(w => w.studentId == studentNum).ToList();

            Assert.NotNull(wishlistEntries);
            int entryToRemovePriority = wishlistEntries.Max(w => w.priority);

            Assert.True(entryToRemovePriority > 0);
            Wishlist entryToRemove = _context.Wishlist.SingleOrDefault(w => w.studentId == studentNum && w.priority == entryToRemovePriority);

            Assert.NotNull(entryToRemove);
            //Get Entry With One Lower Priority (Null)
            int      nextEntryPriority = entryToRemove.priority + 1;
            Wishlist nextEntry         = _context.Wishlist.SingleOrDefault(w => w.studentId == studentNum && w.priority == nextEntryPriority);

            Assert.Null(nextEntry);
            //Get Entry With One Higher Priority
            int      prevEntryPriority = entryToRemove.priority - 1;
            Wishlist prevEntry         = _context.Wishlist.SingleOrDefault(w => w.studentId == studentNum && w.priority == prevEntryPriority);

            Assert.NotNull(prevEntry);
            //Remove Entry
            Wishlist removedEntry = _wishlistService.removeCourseFromStudentWishlist(entryToRemove.studentId, entryToRemove.courseId);

            //Check If Removed Entry Exists
            Assert.NotNull(removedEntry);
            //Check If Previous Entry Did Not Change Priority
            Assert.True(prevEntry.priority == prevEntryPriority);
        }
Пример #4
0
 private string GetWishlistName(Wishlist wishlist)
 {
     if (!String.IsNullOrEmpty(wishlist.Name))
     {
         return(wishlist.Name);
     }
     else
     {
         User u = wishlist.User;
         if (u == null)
         {
             return(string.Empty);
         }
         if (u.IsAnonymous)
         {
             return("Anonymous");
         }
         string fullName = u.PrimaryAddress.FullName;
         if (!string.IsNullOrEmpty(fullName))
         {
             return(fullName);
         }
         return(u.UserName);
     }
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            SetupLayout();

            Wishlist selectedWishlist = e.Parameter as Wishlist;

            selectedWishlist = Runtime.AppController.SetupSelectedWishlist(selectedWishlist);

            //Dont show addbuyer button when wishlist is open
            if (selectedWishlist.IsOpen)
            {
                ButtonAddBuyer.Visibility = Visibility.Collapsed;
            }

            //dont show buttons at startup until wishlist selected
            if (selectedWishlist != null)
            {
                WishlistViewModel = new WishlistViewModel(selectedWishlist);
                DataContext       = WishlistViewModel;
                if (selectedWishlist.Owner.UserId != Runtime.LoggedInUser.UserId)
                {
                    ButtonAdd.Visibility      = Visibility.Collapsed;
                    ButtonAddBuyer.Visibility = Visibility.Collapsed;
                    ButtonRemove.Visibility   = Visibility.Collapsed;
                }
            }
            else
            {
                throw new ArgumentNullException("Always pass a wishlist to this page");
            }
        }
Пример #6
0
        public void removeCourseFromStudentWishlist_HappyPath_PriorityChange()
        {
            //Get Entry
            int      studentNum    = 1;
            int      courseNum     = 1;
            Wishlist entryToRemove = _context.Wishlist.Find(studentNum, courseNum);

            Assert.NotNull(entryToRemove);
            //Get Entry To Remove Priority
            int entryToRemovePriority = entryToRemove.priority;

            Assert.True(entryToRemovePriority > 0);
            //Get Entry With One Lower Priority
            int      nextEntryPriority = entryToRemove.priority + 1;
            Wishlist nextEntry         = _context.Wishlist.SingleOrDefault(w => w.studentId == studentNum && w.priority == nextEntryPriority);

            Assert.NotNull(nextEntry);
            Assert.True(nextEntry.courseId != entryToRemove.courseId);
            //Remove Entry
            Wishlist removedEntry = _wishlistService.removeCourseFromStudentWishlist(entryToRemove.studentId, entryToRemove.courseId);

            //Check If Removed Entry Exists
            Assert.NotNull(removedEntry);
            //Check If Next Entry Priority Is Set To Removed Entry's Priority
            Assert.True(nextEntry.priority == entryToRemovePriority);
        }
Пример #7
0
        private async Task <object> GetWishlist(dynamic o)
        {
            var searchTemplate = this.templateFactory.CreateIriTemplate <WishlistFilter, Collection <WishlistItem> >();
            var uriTemplate    = new UriTemplate.Core.UriTemplate(searchTemplate.Template);

            var templateParams = new Dictionary <string, object>((DynamicDictionary)this.Context.Request.Query);

            var collectionId = uriTemplate.BindByName(templateParams);
            var canonical    = uriTemplate.BindByName(templateParams).ToString();
            var filter       = this.Bind <WishlistFilter>();

            WishlistItem[] wishlistItems = new WishlistItem[0];
            if (this.Context.CurrentUser.HasPermission(Permissions.WriteSources))
            {
                LogTo.Debug("Getting all unique wishlist items");
                wishlistItems = await this.wishlistRepository.FindAdminWishlist(filter.ShowAll.GetValueOrDefault(false));
            }
            else if (this.Context.CurrentUser.IsAuthenticated())
            {
                var user = this.Context.CurrentUser.GetNameClaim();
                LogTo.Debug("Getting items for user {0}", user);
                wishlistItems = await this.wishlistRepository.FindUsersWishlist(user, filter.ShowAll.GetValueOrDefault(true));
            }

            var collection = new Wishlist(searchTemplate)
            {
                Id              = collectionId,
                Members         = wishlistItems,
                TotalItems      = wishlistItems.Length,
                CurrentMappings = templateParams.ToTemplateMappings(searchTemplate),
            };

            return(this.Negotiate.WithModel(collection).WithHeader("Link", $"<{canonical}>; rel=\"canonical\""));
        }
Пример #8
0
        public async Task <IActionResult> PutWishlist(string id, Wishlist wishlist)
        {
            if (id != wishlist.Id)
            {
                return(BadRequest());
            }

            _context.Entry(wishlist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WishlistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #9
0
        public async Task <WishlistModel> Map(Wishlist wishlist)
        {
            var userWishlists = await userRepo.GetUsers(wishlist.GetPeople().Select(s => s.PersonId).ToArray());

            return(new WishlistModel()
            {
                Id = wishlist.Id,
                Name = wishlist.Name,
                People = wishlist.GetPeople().Select(s =>
                                                     new WishlistPersonModel()
                {
                    PersonId = s.PersonId,
                    Giftee = s.Giftee,
                    Name = userWishlists.Single(g => g.Id == s.PersonId).Name,
                    Email = userWishlists.Single(g => g.Id == s.PersonId).Email,
                    PresentIdeas = s.PresentIdeas
                                   .Select(t => new PresentIdeaModel()
                    {
                        Id = t.Id,
                        Description = t.Description,
                        ClaimerId = t.ClaimerId.HasValue == false ?
                                    null :
                                    t.ClaimerId,
                        ClaimerName =
                            t.ClaimerId.HasValue == false ?
                            null :
                            userWishlists.Single(g => g.Id == t.ClaimerId).Name,
                        ClaimerEmail =
                            t.ClaimerId.HasValue == false ?
                            null :
                            userWishlists.Single(g => g.Id == t.ClaimerId).Email
                    }).ToList()
                }).ToList()
            });
        }
Пример #10
0
 public CustomerDTO(Customer C)
 {
     this.IsAdmin   = C.IsAdmin();
     this.Id        = C.Id;
     this.Username  = C.Username;
     this.Email     = C.Email;
     this.Addresses = new List <AddressDTO>();
     foreach (Address a in C.Addresses)
     {
         Addresses.Add(new AddressDTO(a));
     }
     this.AdminComment = C.AdminComment;
     this.Phone        = C.GetAttribute <String>(SystemCustomerAttributeNames.Phone);
     this.FullName     = C.GetAttribute <String>(SystemCustomerAttributeNames.FirstName) + " " + C.GetAttribute <String>(SystemCustomerAttributeNames.LastName);
     this.Active       = C.Active;
     this.Gender       = C.GetAttribute <String>(SystemCustomerAttributeNames.Gender);
     this.Activity     = C.LastActivityDateUtc;
     this.Birthday     = C.GetAttribute <String>(SystemCustomerAttributeNames.DateOfBirth);
     this.Company      = C.GetAttribute <String>(SystemCustomerAttributeNames.Company);
     ShoppingCart      = new List <CartItemDTO>();
     this.Wishlist     = new List <CartItemDTO>();
     foreach (ShoppingCartItem item in C.ShoppingCartItems)
     {
         if (item.ShoppingCartType.Equals(ShoppingCartType.ShoppingCart))
         {
             ShoppingCart.Add(new CartItemDTO(item));
         }
         else
         {
             Wishlist.Add(new CartItemDTO(item));
         }
     }
 }
Пример #11
0
        public void SaveWishlist(UserIdentity userId, Wishlist wishlist)
        {
            //assumption: the manage wishlist page will only allow to use a catalogue at a time (default: Stanley Gibbons)

            // verify which item is already known
            var knownItems = RetrieveKnownItems(wishlist.GetCatalogueReferences(CataloguesInUse.STANLEY_GIBBONS));

            //save items not yet knownn
            var unknownItems = wishlist.Where(wish => !knownItems.Any(itm => wish.IsSameItem(itm.CatalogueReference)));

            itemsRepository.Save(unknownItems);

            var inMemoryWishlist = knownItems.Select(item => item.Id);

            inMemoryWishlist = inMemoryWishlist.Union(unknownItems.Select(item => item.Id));

            // update wishlist
            if (InMemoryDataStore.Wishlists.ContainsKey(userId))
            {
                InMemoryDataStore.Wishlists[userId] = inMemoryWishlist;
                return;
            }

            // add new wishlist
            InMemoryDataStore.Wishlists.Add(userId, inMemoryWishlist);
        }
Пример #12
0
        public ActionResult AddToCartFromWishlist(int id)
        {
            Wishlist wishlist = db.Wishlists.Where(x => x.ProductID == id).FirstOrDefault();

            db.Wishlists.Remove(wishlist);

            OrderDetail od = db.OrderDetails.Where(x => x.ProductID == id).FirstOrDefault();

            if (od != null)
            {
                od.Quantity++;
                od.TotalAmount += od.UnitPrice * (1 - od.Discount);
                od.OrderDate    = DateTime.Now;
            }
            else
            {
                od = new OrderDetail();

                od.ProductID   = id;
                od.CustomerID  = TemporaryUserData.UserID;
                od.UnitPrice   = db.Products.Find(id).UnitPrice;
                od.Discount    = db.Products.Find(id).Discount;
                od.Quantity    = 1;
                od.TotalAmount = od.UnitPrice * od.Quantity * (1 - od.Discount);
                od.OrderDate   = DateTime.Now;
                od.isActive    = true;

                db.OrderDetails.Add(od);
            }

            db.SaveChanges();

            TempData["Wishlist"] = db.Wishlists.ToList();
            return(RedirectToAction("Wishlist"));
        }
Пример #13
0
        public HttpResponseMessage AddToWishlist(Wishlist wish)
        {
            List <Wishlist> wishlist = new List <Wishlist>();
            var             res      = entities.GetWishlist(wish.User_Id).ToList();

            foreach (var item in res)
            {
                wishlist.Add(new Wishlist {
                    User_Id = item.User_Id, Prod_Id = item.Prod_Id
                });
            }
            Wishlist wish1 = wishlist.Where(w => w.User_Id == wish.User_Id && w.Prod_Id == wish.Prod_Id).FirstOrDefault();

            if (wish1 != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Already Present"));
            }
            else
            {
                entities.AddToWishlist(wish.User_Id, wish.Prod_Id);
                entities.SaveChanges();
            }

            return(Request.CreateResponse(HttpStatusCode.OK, "Added to wishlist"));
        }
Пример #14
0
 public static void UpdateWishlist(this Wishlist wishlist, WishlistViewModel wishlistViewModel)
 {
     wishlist.ID          = wishlistViewModel.ID;
     wishlist.UpdatedDate = wishlistViewModel.UpdatedDate;
     wishlist.UserId      = wishlistViewModel.UserId;
     wishlist.ProductId   = wishlistViewModel.ProductId;
 }
Пример #15
0
 public Wishlist WithNoItems()
 {
     _wishlist = new Wishlist {
         BuyerId = WishlistBuyerId, Id = WishlistId
     };
     return(_wishlist);
 }
Пример #16
0
        public string UpdateWishlist(int pid, int mid)
        {
            Wishlist wishlist = new Wishlist();

            wishlist.Pid = pid;
            wishlist.Mid = mid;

            string json = JsonConvert.SerializeObject(wishlist);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"{Apiroot}/wishlist/");

            req.Method      = "POST";
            req.ContentType = "application/json";

            using (var streamWriter = new StreamWriter(req.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            };

            var httpResponse = (HttpWebResponse)req.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                return(streamReader.ReadToEnd());
            }

            //LoadList();
        }
Пример #17
0
        public string AddWishlist(Wishlist wishlist)
        {
            var str = string.Empty;

            try
            {
                var userobj = (from u in context.Users
                               where u.Userid == wishlist.Userid
                               select u).FirstOrDefault();
                var itemobj = (from i in context.Items
                               where i.Itemid == wishlist.Itemid
                               select i).FirstOrDefault();
                var wish = (from w in context.Wishlist
                            where w.Userid == wishlist.Userid && w.Itemid == wishlist.Itemid
                            select w).FirstOrDefault();
                if (userobj == null || itemobj == null || wish != null)
                {
                    return("enter valid data");
                }
                else
                {
                    var res = context.Wishlist.Add(wishlist);
                    context.SaveChanges();
                    str = "sucessfully added";
                }
            }
            catch (Exception e)
            {
                str = e.Message;
                throw (e);
            }
            return(str);
        }
Пример #18
0
        public string DelWishlist(Wishlist wishlist)
        {
            var str = string.Empty;

            try
            {
                var dbwishlist = (from c in context.Wishlist
                                  where c.Itemid == wishlist.Itemid && c.Userid == wishlist.Userid
                                  select c).FirstOrDefault();
                if (dbwishlist != null)
                {
                    context.Wishlist.Remove(dbwishlist);
                    context.SaveChanges();
                    str = "Sucessfully deleted";
                }
                else
                {
                    str = "wishlist item doesnt exist";
                }
            }
            catch (Exception e)
            {
                str = e.Message;
                throw e;
            };
            return(str);
        }
Пример #19
0
        public ActionResult AddToWishlist(int id)
        {
            if (Session["Kullanici"] != null)
            {
                bool addedBefore = false;
                foreach (Wishlist item in db.Wishlists.ToList())
                {
                    if (item.ProductID == id)
                    {
                        addedBefore = true;
                        break;
                    }
                }

                if (!addedBefore)
                {
                    Wishlist wishlist = new Wishlist();
                    wishlist.CustomerID = TemporaryUserData.UserID;
                    wishlist.ProductID  = id;
                    wishlist.IsActive   = true;

                    wishlist.Product = db.Products.Find(id);

                    db.Wishlists.Add(wishlist);
                    db.SaveChanges();
                }

                return(RedirectToAction("ProductDetail", "Product", new { id = id }));
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
        public Wishlist Update(Wishlist updatedWishlist)
        {
            DeleteById(updatedWishlist.Id);
            Wishlists.Add(updatedWishlist);

            return(updatedWishlist);
        }
Пример #21
0
        public async Task <IActionResult> Edit(int id, [Bind("Id")] Wishlist wishlist)
        {
            if (id != wishlist.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(wishlist);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WishlistExists(wishlist.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(wishlist));
        }
        Wishlist IWishlistService.AddOrUpdateWishlist(WishlistDTO wishlistDTO)
        {
            Wishlist wishlist  = Mapper.Map <WishlistDTO, Wishlist>(wishlistDTO);
            var      returnObj = wishlistRepository.AddWishlist(wishlist);

            return(returnObj);
        }
        public Wishlist AddWishlist(WishlistDTO wishlistDTO)
        {
            Wishlist wishlist = Mapper.Map <WishlistDTO, Wishlist>(wishlistDTO);

            wishlistRepository.AddWishlist(wishlist);
            return(null);
        }
        public async Task <IActionResult> PutWishlist(int id, Wishlist wishlist)
        {
            // NLog
            string message = $"(API Server) -Try to PUT (update) Wishlist " + id + "(Id) - Controller : WishlistsController; " +
                             "Actionname: PutWishlist(...); HTTP method : HttpPut; Time: " + DateTime.Now + "\n";

            _logger.Info(message);

            try
            {
                _context.Entry(wishlist).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                // NLog Framework Call

                // LOG INFO
                _logger.Info("INFORMATION DETAILS, Exception occured during operation : " + message);
                _logger.Info("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG WARN
                _logger.Warn("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Warn("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG ERROR
                _logger.Error("ERROR DETAILS, Exception occured during operation : " + message);
                _logger.Error("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG TRACE
                _logger.Trace("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Trace("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG FATAL
                _logger.Fatal("FATAL DETAILS, Exception occured during operation : " + message);
                _logger.Fatal("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG DEGUG
                _logger.Debug("DEGUG DETAILS, Exception occured during operation : " + message);
                _logger.Debug("EXCEPTION DETAILS: " + ex.Message + "\n");

                if (id != wishlist.Id)
                {
                    return(BadRequest());
                }
                else if (!WishlistExists(id))
                {
                    return(NotFound());
                }

                return(NotFound());
            }

            return(NoContent());
        }
Пример #25
0
        private async void Button_weiger(object sender, RoutedEventArgs e)
        {
            Button   btn      = (Button)sender;
            Wishlist wishlist = (Wishlist)btn.DataContext;
            await app.repository.weigerUitnodiging(wishlist);

            aanvragenlist.Remove(wishlist);
        }
        /// <summary>
        /// Move the basket item at the given index to the given wishlist
        /// </summary>
        /// <param name="index">Index of the item to move</param>
        /// <param name="wishlist">The wishlist to move to</param>
        public void MoveToWishlist(int index, Wishlist wishlist)
        {
            BasketItem item = this[index];

            wishlist.Items.Add(item);
            wishlist.Save();
            this.DeleteAt(index);
        }
Пример #27
0
        public async Task <bool> IncreaseProductQuantity(Wishlist wishlistID, int quantity)
        {
            var wishlist = _wishlist.IncreaseProductQuantity(wishlistID, quantity);

            await Edit(wishlist.Result.ID, wishlist.Result);

            return(true);
        }
 // Todo move claim check logic inside this function
 private bool CheckIfOwner(Wishlist wishlist, string userEmail)
 {
     if (wishlist.OwnerId != userEmail)
     {
         return(false);
     }
     return(true);
 }
Пример #29
0
        private async void AddItemToWishlist(Wishlist wishlist)
        {
            string url = "http://localhost:57620/api/mycity/wishlist";

            var serializedWishlist = JsonConvert.SerializeObject(wishlist);
            var content            = new StringContent(serializedWishlist, Encoding.UTF8, "application/json");
            var result             = await client.PostAsync(url, content);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Wishlist wishlist = db.Wishlists.Find(id);

            db.Wishlists.Remove(wishlist);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #31
0
 public ActionResult Create(FormCollection collection)
 {
     myHandler = new BusinessLogicHandler();
     list = new Wishlist();
     try
     {
         return View();
     }
     catch
     {
         return View();
     }
 }
Пример #32
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         myHandler = new BusinessLogicHandler();
         list = new Wishlist();
         TryUpdateModel(list);
         if (ModelState.IsValid)
         {
             //myHandler.UpdateWishlist(list);
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }