Ejemplo n.º 1
0
        public Story SaveStory(Story story)
        {
            if (story != null)
            {
                if (story.StoryId == 0)  // this is new
                {
                    SetPriorityForSave(story, 0, story.Priority);
                    _ScrumTimeEntities.AddToStories(story);
                }
                else  // the story exists
                {
                    _ScrumTimeEntities.AttachTo("Stories", story);

                    ScrumTimeEntities freshScrumTimeEntities =
                        new ScrumTimeEntities(_ScrumTimeEntities.Connection.ConnectionString);
                    Story existingStory = GetStoryById(freshScrumTimeEntities, story.StoryId);
                    if (existingStory != null && existingStory.StoryId > 0)
                    {
                        SetPriorityForSave(story, existingStory.Priority, story.Priority);
                    }
                    else
                    {
                        throw new Exception("The story no longer exists.");
                    }
                    _ScrumTimeEntities.ObjectStateManager.ChangeObjectState(story, System.Data.EntityState.Modified);
                }
                _ScrumTimeEntities.SaveChanges();
            }
            return story;
        }
Ejemplo n.º 2
0
 public static Story GetStoryById(ScrumTimeEntities scrumTimeEntities, int id)
 {
     Story story = null;
     var results = from s in scrumTimeEntities.Stories
                   where s.StoryId == id
                   select s;
     if (results.Count() > 0)
         story = results.First<Story>();
     else
         story = new Story();
     return story;
 }
Ejemplo n.º 3
0
 public void AddNewStory()
 {
     ScrumTimeEntities scrumTimeEntities = new ScrumTimeEntities();
     StoryService storyService = new StoryService(scrumTimeEntities);
     Story story = new Story()
     {
         Narrative = "Test story",
         Points = 8,
         Priority = 2,
         ProductId = 1,
         UserDefinedId = "not set"
     };
     storyService.SaveStory(story);
 }
Ejemplo n.º 4
0
        public void DeleteStory()
        {
            ScrumTimeEntities scrumTimeEntities = new ScrumTimeEntities();
            StoryService storyService = new StoryService(scrumTimeEntities);
            Story story = new Story()
            {
                Narrative = "Test story for deletion test.",
                Points = 8,
                Priority = 2,
                ProductId = 1,
                UserDefinedId = "not set"
            };
            storyService.SaveStory(story);

            storyService.DeleteStory(story.StoryId);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Stories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStories(Story story)
 {
     base.AddObject("Stories", story);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Create a new Story object.
 /// </summary>
 /// <param name="storyId">Initial value of the StoryId property.</param>
 /// <param name="narrative">Initial value of the Narrative property.</param>
 /// <param name="points">Initial value of the Points property.</param>
 /// <param name="priority">Initial value of the Priority property.</param>
 /// <param name="productId">Initial value of the ProductId property.</param>
 public static Story CreateStory(global::System.Int32 storyId, global::System.String narrative, global::System.Int32 points, global::System.Int32 priority, global::System.Int32 productId)
 {
     Story story = new Story();
     story.StoryId = storyId;
     story.Narrative = narrative;
     story.Points = points;
     story.Priority = priority;
     story.ProductId = productId;
     return story;
 }
Ejemplo n.º 7
0
        public virtual ActionResult Save(FormCollection collection)
        {
            try
            {
                string id = collection.Get("storyId");
                bool newStory = false;
                if (id == null || id == "0")
                {
                    id = "0";
                    newStory = true;
                }
                string priority = collection.Get("priority");
                string originalPriority = collection.Get("originalPriority");
                string userDefinedId = collection.Get("userDefinedId");
                string narrative = collection.Get("narrative");
                string points = collection.Get("points");
                string sprintId = collection.Get("sprintId");
                int? sprintIdAsInt = (sprintId == null) ? null : (int?)Int32.Parse(sprintId);
                sprintIdAsInt = (sprintIdAsInt != null && sprintIdAsInt > 0) ? sprintIdAsInt : null;
                // TODO:  Validate the story data before saving
                // TODO:  Set the correct product id
                Story story = new Story()
                {
                    StoryId = Int32.Parse(id),
                    Narrative = narrative,
                    Points = Int32.Parse(points),
                    Priority = Int32.Parse(priority),
                    ProductId = SessionHelper.GetCurrentProductId(User.Identity.Name, Session),
                    UserDefinedId = userDefinedId,
                    SprintId = sprintIdAsInt
                };
                _StoryService.SaveStory(story);

                if (newStory || (priority != originalPriority))
                    return RedirectToAction("ListByPriority");
                else
                    return RedirectToAction("ReadOnly", new { id = Int32.Parse(id) });
            }
            catch
            {
                return View();  // TODO:  Handle displaying the exception condition
            }
        }
Ejemplo n.º 8
0
        // Set both priorities to zero or less for a delete scenario
        protected void SetPriorityForSave(Story story, int currentPriority, int targetPriority)
        {
            int totalStories = _ScrumTimeEntities.Stories.Count();

            if (currentPriority < 1) // this is a new story
            {
                targetPriority = AdjustToWithinBounds(targetPriority, totalStories + 1);
                story.Priority = targetPriority;
                IncreasePriorityValuesInclusive(targetPriority, totalStories);
            }
            else  // this is an existing story
            {
                targetPriority = AdjustToWithinBounds(targetPriority, totalStories);
                story.Priority = targetPriority;
                if (currentPriority < targetPriority)
                {
                    DecreasePriorityValuesInclusive(currentPriority + 1, targetPriority);
                }
                else if (currentPriority > targetPriority)
                {
                    IncreasePriorityValuesInclusive(targetPriority, currentPriority - 1);
                }
            }
        }