Example #1
0
        public ActionResult Create(IFormCollection collection)
        {
            int reviewId;

            if (!int.TryParse(collection["reviewId"], out reviewId))
            {
                return(RedirectToAction("Index"));
            }

            try
            {
                var review   = _context.Review.SingleOrDefault(r => r.ReviewId == int.Parse(collection["reviewId"]));
                var member   = _context.Member.SingleOrDefault(m => m.MemberId == int.Parse(collection["member"]));
                var dateTime = DateTime.Parse(collection["date"]);
                var time     = int.Parse(collection["time"]);
                _context.ReviewTime.Add(new ReviewTime
                {
                    Review = review,
                    Member = member,
                    Date   = dateTime,
                    Time   = time
                });
                _context.SaveChanges();

                TempData["message"] = "時間追加に成功";
                return(RedirectToAction("Index"));
            }
            catch
            {
                TempData["message"] = "時間追加に失敗";
                return(RedirectToAction("Index"));
            }
        }
Example #2
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                // Reviewがあるか確認
                var project = _context.Project.Single(p => p.ProjectId == int.Parse(collection["project"]));
                var version = _context.Version.Single(v => v.ReleaseId == int.Parse(collection["version"]));
                var output  = _context.Output.Single(o => o.OutputId == int.Parse(collection["output"]));
                var review  = _context.Review.Where(r => r.Project == project && r.Version == version && r.Output == output).ToArray();
                if (review.Count() > 0)
                {
                    ViewData["message"]  = "すでにReviewが存在します。";
                    ViewData["Members"]  = _context.Member.ToList();
                    ViewData["Projects"] = _context.Project.ToList();
                    ViewData["Outputs"]  = _context.Output.ToList();
                    ViewData["Versions"] = _context.Version.ToList();
                    return(View());
                }

                var ticket = int.Parse(collection["ticket"]);
                var author = _context.Member.SingleOrDefault(m => m.MemberId == int.Parse(collection["author"]));

                // ないので作成
                _context.Review.Add(new Review
                {
                    Project = project,
                    Version = version,
                    Ticket  = ticket,
                    Output  = output,
                    Author  = author
                });
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ViewData["message"] = "";
                return(View());
            }
        }