Example #1
0
        public async Task <IActionResult> PostSprint([FromRoute] int productId, [FromBody] SprintBacklog sprint)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (sprint.ProductId != productId)
            {
                return(BadRequest());
            }

            var userId  = int.Parse(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
            var product = await productService.GetProductById(productId);

            if (product == null)
            {
                return(NotFound(new { message = "Product not found." }));
            }

            if (product.Owner.Id != userId)
            {
                return(Forbid());
            }

            var savedSprint = await sprintService.SaveSprint(sprint);

            return(CreatedAtAction("PostSprint", new { prdouctId = productId }, savedSprint));
        }
Example #2
0
        public ActionResult Save(FormCollection collection)
        {
            try
            {
                string id        = collection.Get("sprintId");
                string productId = collection.Get("productId");
                bool   newSprint = false;
                if (id == null || id == "0")
                {
                    id        = "0";
                    newSprint = true;
                }
                string name        = collection.Get("name");
                string description = collection.Get("description");
                string start       = collection.Get("start");
                string finish      = collection.Get("finish");
                // TODO:  Validate the sprint data before saving
                // TODO:  Set the correct product id
                Sprint sprint = new Sprint()
                {
                    SprintId    = Int32.Parse(id),
                    ProductId   = Int32.Parse(productId),
                    Name        = name,
                    Description = description,
                    StartDate   = DateTime.Parse(start),
                    FinishDate  = DateTime.Parse(finish)
                };
                _SprintService.SaveSprint(sprint);

                if (newSprint)
                {
                    return(RedirectToAction("ListByStartDateDesc", new { productId = Int32.Parse(productId) }));
                }
                else
                {
                    return(RedirectToAction("ReadOnly", new { id = Int32.Parse(id) }));
                }
            }
            catch (Exception ex)
            {
                return(View());  // TODO:  Handle displaying the exception condition
            }
        }