コード例 #1
0
        public IHttpResponse AddGamePost(IHttpRequest req)
        {
            var isValid     = true;
            var title       = string.Empty;
            var description = string.Empty;
            var imageUrl    = string.Empty;
            var price       = 0.00M;
            var size        = 0.00D;
            var videoUrl    = string.Empty;
            var releaseDate = string.Empty;

            if (req.FormData.ContainsKey("title") && req.FormData.ContainsKey("description") &&
                req.FormData.ContainsKey("image-url") && req.FormData.ContainsKey("price") &&
                req.FormData.ContainsKey("size") && req.FormData.ContainsKey("video-url") &&
                req.FormData.ContainsKey("release-date"))
            {
                title       = req.FormData["title"];
                description = req.FormData["description"];
                imageUrl    = req.FormData["image-url"];
                price       = decimal.Parse(req.FormData["price"]);
                size        = double.Parse(req.FormData["size"]);
                videoUrl    = req.FormData["video-url"];
                releaseDate = req.FormData["release-date"];
            }

            isValid = this.isValidGameInformation(title, description, size, price, imageUrl, videoUrl);

            DateTime parsedDate;

            try
            {
                parsedDate = DateTime.ParseExact(releaseDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);

                if (isValid)
                {
                    games.AddGameToDb(title, description, size, price, imageUrl, videoUrl, parsedDate);
                }
            }
            catch
            {
                this.ViewData["<!--ErrorDate-->"] = "<div class=\"col - md - 4\">" +
                                                    "<p class=\"text-danger\">Invalid Date! Date has to be in format dd-mm-yyyy" +
                                                    "</div>";
                isValid = false;
            }

            return(new ViewResponse(HttpStatusCode.Ok, new HtmlView(@"admin\addgame", this.ViewData, req)));
        }