Example #1
0
        /// <summary>
        /// Updates a element's property by creating a new element, 
        /// updating the parent and child pointers
        /// repoints the parent's child pointer to this
        /// repoints the children's parent pointer to this.
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public ElementView updateElement(ElementView element, bool autoclose)
        {
            ElementView oldElement = this.requestList.Data.Where(x => x.ID == element.Parent.ID).FirstOrDefault().ElementList.Where(y => y.ID == element.ID).FirstOrDefault();

            if (!autoclose && oldElement.Status.ID == element.Status.ID && this.elementStatusList.Data.Where(x => x.ID == element.Status.ID).FirstOrDefault().Text.Equals("Complete"))
                throw new InvalidOperationException("The status is closed. You cannot update an element that is closed.");

            element.isNew = false;
            element.Status = this.elementStatusList.Data.Where(x => x.ID == element.Status.ID).FirstOrDefault();
            string status = element.Status.Text.ToLower();
            if (status.Equals("complete") || status.Equals("rejected")) {
                if (element.Resolution == null || element.Resolution.Length < 1)
                    throw new ArgumentException("You are closing this element. Please provide a resolution.");
                element.setClosed();
            }

            element.setLastUpdated();

            ElementView e = convertElement(this.svc.updateElement(element));

            e.Parent = oldElement.Parent;
            Parallel.ForEach(oldElement.Note, note => {
                note.Parent = e;
            });
            e.Note = oldElement.Note;

            // change the pointer in the requestList to point to this object
            foreach (RequestView rv in this.requestList.Data.ToList())
                foreach (ElementView ev in rv.ElementList.ToList())
                    if (ev.ID == element.ID) {
                        rv.ElementList.Remove(ev);
                        rv.ElementList.Add(e);
                        continue;
                    }

            HttpContext.Current.Application.Lock();
            HttpContext.Current.Application["Request"] = this.requestList;
            HttpContext.Current.Application.UnLock();
            return e;
        }
Example #2
0
        /// <summary>
        /// Saves a new element into the requestList Tree. \n
        /// Point to parent Request
        /// Add element to parent Request ElementList
        /// </summary>
        /// <param name="element">The new element to add</param>
        /// <returns>The updated element with the pointers updated</returns>
        public ElementView saveElement(ElementView element)
        {
            if (element.Summary == null || element.Summary.Length < 1)
                throw new ArgumentException("Summary is Required.");

            element.Status = this.elementStatusList.Data.Where(x => x.ID == element.Status.ID).FirstOrDefault();

            element.Status = this.elementStatusList.Data.Where(x => x.ID == element.Status.ID).FirstOrDefault();
            string status = element.Status.Text.ToLower();
            element.isNew = false;
            if (status.Equals("complete") || status.Equals("rejected")) {
                if (element.Resolution == null || element.Resolution.Length < 1)
                    throw new ArgumentException("You are closing this element. Please provide a resolution.");
                element.setClosed();
            }
            element.setLastUpdated();

            ElementView e = convertElement(this.svc.saveElement(element));
            RequestView r = getRequest(element.Parent.ID);
            e.Parent = r;
            r.ElementList.Add(e);

            HttpContext.Current.Application.Lock();
            HttpContext.Current.Application["Request"] = this.requestList;
            HttpContext.Current.Application.UnLock();
            return e;
        }