示例#1
0
        public Boolean AddOrUpdate(Project ItemToBeSaved)
        {
            Project ExistingItem = _context.Project.Where(x => x.ID == ItemToBeSaved.ID).FirstOrDefault();

            try
            {
                if (ExistingItem == null)
                {
                    //New logic
                    ItemToBeSaved.CreateDate = DateTime.Now;
                    _context.Project.Add(ItemToBeSaved);
                    _context.SaveChanges();
                }
                else
                {
                    //update logic
                    //ExistingItem = ItemToBeSaved;
                    ExistingItem.Name        = ItemToBeSaved.Name;
                    ExistingItem.Description = ItemToBeSaved.Description;
                    ExistingItem.Creator     = ItemToBeSaved.Creator;
                    _context.Project.Update(ExistingItem);
                    _context.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public Boolean AddOrUpdate(BoardItem ItemToBeSaved)
        {
            BoardItem ExistingItem = _context.BoardItem.Where(x => x.ID == ItemToBeSaved.ID).FirstOrDefault();

            try
            {
                if (ExistingItem == null)
                {
                    //New logic
                    ItemToBeSaved.CreateDate  = DateTime.Now;
                    ItemToBeSaved.LastUpdated = DateTime.Now;
                    _context.BoardItem.Add(ItemToBeSaved);
                    _context.SaveChanges();
                }
                else
                {
                    //update logic
                    //ExistingItem = ItemToBeSaved;
                    ExistingItem.Description = ItemToBeSaved.Description;
                    ExistingItem.Effort      = ItemToBeSaved.Effort;
                    ExistingItem.ItemType    = ItemToBeSaved.ItemType;
                    ExistingItem.Priority    = ItemToBeSaved.Priority;
                    ExistingItem.State       = ItemToBeSaved.State;
                    ExistingItem.Title       = ItemToBeSaved.Title;
                    ExistingItem.LastUpdated = DateTime.Now;
                    ExistingItem.Iteration   = ItemToBeSaved.Iteration;
                    ExistingItem.OwnerName   = ItemToBeSaved.OwnerName;
                    ExistingItem.ParentID    = ItemToBeSaved.ParentID;

                    _context.BoardItem.Update(ExistingItem);
                    _context.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }