Exemplo n.º 1
0
        // Display All Gifts
        // GET: Gifts
        public ActionResult Index()
        {
            // get all gifts from ??? (service class)
            var gifts = GiftService.GetAllGifts();

            return(View(gifts));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            var updatedGift = new Gift
            {
                Contents = collection["Contents"],
                Hints    = collection["Hints"],
                Depth    = double.Parse(collection["Depth"]),
                Height   = double.Parse(collection["Height"]),
                Weight   = double.Parse(collection["Weight"]),
                IsOpened = bool.Parse(collection["IsOpened"]),
                Width    = double.Parse(collection["Width"]),
                Id       = id
            };

            try
            {
                // accept  & parse the input (formcollection)
                // save it to our database
                GiftService.UpdateGift(updatedGift);
                // redirect to the correct page
                return(RedirectToAction("Index"));
            }
            catch (SqlException ex)
            {
                ViewBag.ErrorMessage = "There was issue with you Gift, Try again.";
                ViewBag.ErrorTitleThatisSomethingCollThatisNotWhereElseInmYProgram = true;
                return(View(updatedGift));
            }
        }
Exemplo n.º 3
0
        public async Task FetchGift()
        {
            using (var context = new ApplicationDbContext(Options))
            {
                GiftService giftService = new GiftService(context);
                UserService userService = new UserService(context);

                var user = new User
                {
                    FirstName = "Inigo",
                    LastName  = "Montoya"
                };

                user = await userService.AddUser(user);

                var gift = new Gift
                {
                    Title             = "Sword",
                    OrderOfImportance = 1,
                    UserId            = user.Id
                };

                var persistedGift = await giftService.AddGift(gift);

                Assert.AreNotEqual(0, persistedGift.Id);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                GiftService giftService   = new GiftService(context);
                var         retrievedGift = await giftService.GetGift(1);

                Assert.AreEqual("Sword", retrievedGift.Title);
            }
        }
        public async Task AddGift()
        {
            using (var context = new ApplicationDbContext(Options))
            {
                GiftService giftService = new GiftService(context);
                UserService userService = new UserService(context);

                var user = new User
                {
                    FirstName = "Inigo",
                    LastName  = "Montoya"
                };

                user = await userService.AddUser(user);

                var gift = new Gift
                {
                    Title             = "Sword",
                    OrderOfImportance = 1
                };

                var persistedGift = await giftService.AddGiftToUser(user.Id, gift);

                Assert.AreNotEqual(0, persistedGift.Id);
            }
        }
Exemplo n.º 5
0
        private GiftService CreateGiftService()
        {
            var userID  = Guid.Parse(User.Identity.GetUserId());
            var service = new GiftService(userID);

            return(service);
        }
Exemplo n.º 6
0
        // GET: Gift
        public ActionResult Index()
        {
            var userID  = Guid.Parse(User.Identity.GetUserId());
            var service = new GiftService(userID);
            var model   = service.GetGift();

            return(View(model));
        }
Exemplo n.º 7
0
        public GiftController(GiftOrderService orderService, GiftService giftService, WeChatService weChatService, CHISEntitiesSqlServer db) : base(db)
        {
            _giftService = giftService;

            _orderService = orderService;

            _weChatService = weChatService;
        }
Exemplo n.º 8
0
        public async Task <ActionResult <ICollection <GiftViewModel> > > GetGiftsForUser(int userId)
        {
            if (userId <= 0)
            {
                return(NotFound());
            }
            List <Gift> databaseUsers = await GiftService.GetGiftsForUser(userId);

            return(Ok(databaseUsers.Select(x => Mapper.Map <GiftViewModel>(x)).ToList()));
        }
Exemplo n.º 9
0
        public async Task UpdateGift()
        {
            using (var context = new ApplicationDbContext(Options))
            {
                GiftService giftService = new GiftService(context);
                UserService userService = new UserService(context);

                var user = new User
                {
                    FirstName = "Inigo",
                    LastName  = "Montoya"
                };

                user = await userService.AddUser(user);

                var gift = new Gift
                {
                    Title             = "Sword",
                    OrderOfImportance = 1,
                    UserId            = user.Id
                };

                var persistedGift = await giftService.AddGift(gift);

                Assert.AreNotEqual(0, persistedGift.Id);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                GiftService giftService = new GiftService(context);
                UserService userService = new UserService(context);

                var users = await userService.FetchAll();

                var gifts = await giftService.GetGiftsForUser(users[0].Id);

                Assert.IsTrue(gifts.Count > 0);

                gifts[0].Title = "Horse";
                await giftService.UpdateGift(gifts[0]);
            }

            using (var context = new ApplicationDbContext(Options))
            {
                GiftService giftService = new GiftService(context);
                UserService userService = new UserService(context);

                var users = await userService.FetchAll();

                var gifts = await giftService.GetGiftsForUser(users[0].Id);

                Assert.IsTrue(gifts.Count > 0);
                Assert.AreEqual("Horse", gifts[0].Title);
            }
        }
Exemplo n.º 10
0
 public GiftController(GiftService giftService,
                       GiftOrderService giftOrderService,
                       PointsDetailService pointsService,
                       ILogger <GiftController> logger,
                       CHISEntitiesSqlServer db) : base(db)
 {
     _giftService      = giftService;
     _giftOrderService = giftOrderService;
     _pointsService    = pointsService;
     _logger           = logger;
 }
Exemplo n.º 11
0
        public async Task <ActionResult <GiftViewModel> > GetGift(int id)
        {
            var gift = await GiftService.GetGift(id);

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

            return(Ok(Mapper.Map <GiftViewModel>(gift)));
        }
Exemplo n.º 12
0
        public GiftServiceTests()
        {
            service = new GiftService(new PorticoConfig {
                SecretApiKey = "skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw"
            });

            card = new GiftCard {
                Number = "5022440000000000007"
            };;
            replacement = new GiftCard {
                TrackData = "%B5022440000000000098^^391200081613?;5022440000000000098=391200081613?"
            };
        }
Exemplo n.º 13
0
        //public ActionResult Index(int? eventId)
        // The stupidest thing : the parameter must be called id.  Otherwise, the parameter will be assigned null
        public ActionResult Index(int id)
        {
            // refactor GiftService so, rather than setting a Guid _userId,
            // we set an int _eventId
            // so we can use the _eventId of the event which all the gifts are connected to
            int eventId = id;
            var service = new GiftService(eventId);

            // get the list of gifts
            //   where Gift.RegistryEvent.RegistryEventId == eventId
            var model = service.GetGiftsByEvent();

            return(View(model));
        }
        public GiftServiceTests()
        {
            service = new GiftService(new GatewayConfig {
                SecretApiKey = "skapi_cert_MaePAQBr-1QAqjfckFC8FTbRTT120bVQUlfVOjgCBw",
                ServiceUrl   = "https://cert.api2.heartlandportico.com"
            });

            card = new GiftCard {
                Number = "5022440000000000007"
            };;
            replacement = new GiftCard {
                TrackData = "%B5022440000000000098^^391200081613?;5022440000000000098=391200081613?"
            };
        }
Exemplo n.º 15
0
 private void SetStatus(string json)
 {
     try
     {
         XmasStatus xmasStatus = JsonUtility.FromJson <XmasStatus>(json);
         if (xmasStatus != null)
         {
             status = xmasStatus;
             if (GiftService.statusUpdated != null)
             {
                 GiftService.statusUpdated(status);
             }
         }
     }
     catch (Exception exception)
     {
         Debug.LogException(exception);
     }
 }
Exemplo n.º 16
0
 public ActionResult Open(int id, FormCollection collection)
 {
     GiftService.OpenGift(id);
     return(RedirectToAction("Index"));
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            ICollection <Sweet> sweets = new List <Sweet>
            {
                new ChocolateCandy("", 23, 45, 55),
                new ChocolateCandy("", 22, 40, 555),
                new BrittleСandy("", 10, 42, 11),
                new BrittleСandy("", 8, 80, 5),
                new LiquorCandy("", 7, 5, 555),
                new CurdCookie("", 111, "", 2),
                new ChocolateCookie("", 75, "", 10),
                new OatCookie("", 30, ""),
                new Chocolate("", 200, 25, 50),
                new Marshmallow("", 1, "", 10)
            };

            Gift         gift        = new Gift();
            IGiftService giftService = new GiftService();

            giftService.AddSweetsToGift(gift, sweets);
            int  choose;
            bool flag = true;

            while (flag)
            {
                Console.WriteLine("1-print all sweets in gift\n" +
                                  "2-Search by sugar value\n" +
                                  "3-Sort by weight\n" +
                                  "4-Get total gift weight\n" +
                                  "5-Sort sweets which have sugar\n" +
                                  "6-Sort sweets which have chocolate\n");

                choose = Convert.ToInt32(Console.ReadLine());
                Console.Clear();
                switch (choose)
                {
                case 1:
                {
                    Console.WriteLine("All sweets");
                    giftService.PrintAll(gift.Sweets);
                    break;
                }

                case 2:
                {
                    Console.Write("Min value");
                    int min = int.Parse(Console.ReadLine());
                    Console.Write("Max value");
                    int max = int.Parse(Console.ReadLine());
                    Console.WriteLine();
                    giftService.PrintAll(giftService.SearchSugar(gift.Sweets, min, max));
                    break;
                }

                case 3:
                {
                    Console.WriteLine("All sweets sorted by weight");
                    giftService.PrintAll(giftService.SortByWeight(gift.Sweets));
                    Console.WriteLine();
                    break;
                }

                case 4:
                {
                    Console.WriteLine("Gift weight");
                    Console.WriteLine($"{giftService.CalculateWeight(gift.Sweets)}g");
                    Console.WriteLine();
                    break;
                }

                case 5:
                {
                    Console.WriteLine("Sort sweets which have sugar");
                    giftService.PrintAll(giftService.SortOnlySugarable(gift.Sweets));
                    Console.WriteLine();
                    break;
                }

                case 6:
                {
                    Console.WriteLine("Sort sweets which have chocolate");
                    giftService.PrintAll(giftService.SortOnlyChocolable(gift.Sweets));
                    Console.WriteLine();
                    break;
                }

                case 0:
                {
                    flag = false;
                    break;
                }

                default:
                {
                    break;
                }
                }
            }

            Console.WriteLine();
        }
Exemplo n.º 18
0
 public GiftController(GiftService giftService)
 {
     _giftService = giftService;
 }
Exemplo n.º 19
0
 public HomeController(GiftService giftService)
 {
     _giftService = giftService;
 }
Exemplo n.º 20
0
        private GiftService CreateGiftService()
        {
            var service = new GiftService();

            return(service);
        }
Exemplo n.º 21
0
 private void Awake()
 {
     instance = this;
 }
Exemplo n.º 22
0
        public ActionResult Open(int id)
        {
            var gift = GiftService.GetGift(id);

            return(View(gift));
        }
Exemplo n.º 23
0
        public async Task <ActionResult <GiftViewModel> > CreateGift(GiftInputViewModel viewModel)
        {
            var createdGift = await GiftService.AddGift(Mapper.Map <Gift>(viewModel));

            return(CreatedAtAction(nameof(GetGift), new { id = createdGift.Id }, Mapper.Map <GiftViewModel>(createdGift)));
        }
Exemplo n.º 24
0
        public ActionResult GetGiftsData()
        {
            var result = new GiftService().GetGiftsData();

            return(Content(JsonHelper.SerializeObject(result)));
        }