コード例 #1
0
        // Display All Gifts
        // GET: Gifts
        public ActionResult Index()
        {
            // get all gifts from ??? (service class)
            var gifts = GiftService.GetAllGifts();

            return(View(gifts));
        }
コード例 #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));
            }
        }
コード例 #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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        private GiftService CreateGiftService()
        {
            var userID  = Guid.Parse(User.Identity.GetUserId());
            var service = new GiftService(userID);

            return(service);
        }
コード例 #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));
        }
コード例 #7
0
ファイル: GiftController.cs プロジェクト: iJzFan/backup
        public GiftController(GiftOrderService orderService, GiftService giftService, WeChatService weChatService, CHISEntitiesSqlServer db) : base(db)
        {
            _giftService = giftService;

            _orderService = orderService;

            _weChatService = weChatService;
        }
コード例 #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()));
        }
コード例 #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);
            }
        }
コード例 #10
0
ファイル: GiftController.cs プロジェクト: iJzFan/backup
 public GiftController(GiftService giftService,
                       GiftOrderService giftOrderService,
                       PointsDetailService pointsService,
                       ILogger <GiftController> logger,
                       CHISEntitiesSqlServer db) : base(db)
 {
     _giftService      = giftService;
     _giftOrderService = giftOrderService;
     _pointsService    = pointsService;
     _logger           = logger;
 }
コード例 #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)));
        }
コード例 #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?"
            };
        }
コード例 #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));
        }
コード例 #14
0
        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?"
            };
        }
コード例 #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);
     }
 }
コード例 #16
0
 public ActionResult Open(int id, FormCollection collection)
 {
     GiftService.OpenGift(id);
     return(RedirectToAction("Index"));
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: pzanevskiy/EPAM_Tasks
        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();
        }
コード例 #18
0
ファイル: GiftController.cs プロジェクト: iJzFan/backup
 public GiftController(GiftService giftService)
 {
     _giftService = giftService;
 }
コード例 #19
0
 public HomeController(GiftService giftService)
 {
     _giftService = giftService;
 }
コード例 #20
0
        private GiftService CreateGiftService()
        {
            var service = new GiftService();

            return(service);
        }
コード例 #21
0
 private void Awake()
 {
     instance = this;
 }
コード例 #22
0
        public ActionResult Open(int id)
        {
            var gift = GiftService.GetGift(id);

            return(View(gift));
        }
コード例 #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)));
        }
コード例 #24
0
ファイル: GoodController.cs プロジェクト: iteming/CHIHC
        public ActionResult GetGiftsData()
        {
            var result = new GiftService().GetGiftsData();

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