Ejemplo n.º 1
0
        /// <summary>
        /// Add tag to database
        /// </summary>
        /// <param name="userId">User identifier</param>
        /// <param name="name">Caption for new tag</param>
        /// <param name="parentId">Parent identifier for tag</param>
        /// <returns>Execution result with identifier for new tag</returns>
        public AddResponse Add(int userId, string name, int parentId)
        {
            var addResponse = new AddResponse();
            if (HasUserAccess(userId, parentId))
            {
                if (string.IsNullOrEmpty(name))
                {
                    addResponse.IsError = true;
                    addResponse.Errors.Add(Error.TagNameHasNotBeenSet);
                }
                else
                {
                    var tag = new Tag();
                    tag.Parent = GetById(userId, parentId).Object;
                    tag.Name = name;
                    tag.User = new UserRepository(context).GetById(userId, userId).Object;
                    context.Tags.AddObject(tag);
                    context.Save();
                    addResponse.Id = tag.Id;
                }
            }
            else
            {
                addResponse.IsError = true;
                addResponse.Errors.Add(Error.UserDoesNotHaveAccess);
            }

            return addResponse;
        }
Ejemplo n.º 2
0
     private void FixupTag(Tag previousValue)
     {
         if (previousValue != null && previousValue.ExpenseRecords.Contains(this))
         {
             previousValue.ExpenseRecords.Remove(this);
         }
 
         if (Tag != null)
         {
             if (!Tag.ExpenseRecords.Contains(this))
             {
                 Tag.ExpenseRecords.Add(this);
             }
         }
     }
Ejemplo n.º 3
0
 /// <summary>
 /// Delete tag from datase
 /// </summary>
 /// <param name="userId">User identifier</param>
 /// <param name="entity">Tag identifier</param>
 /// <returns>Execution result</returns>
 public Response Delete(int userId, Tag entity)
 {
     var response = new Response();
     if (entity != null && HasUserAccess(userId, entity.Id))
     {
         while (entity.Children.Count > 0)
         {
             Delete(userId, entity.Children.First());
         }
         context.Tags.DeleteObject(entity);
         context.Save();
     }
     else
     {
         response.IsError = true;
         response.Errors.Add(Error.UserDoesNotHaveAccess);
     }
     
     return response;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Add new tag to database
 /// </summary>
 /// <param name="userId">User Identifier</param>
 /// <param name="entity">Tag</param>
 /// <returns>Tag identifier</returns>
 public AddResponse Add(int userId, Tag entity)
 {
     var addResponse = new AddResponse();
     if (entity == null)
     {
         addResponse.IsError = true;
         addResponse.Errors.Add(Error.TagNameHasNotBeenSet);
     }
     else
     {
         entity.User = new UserRepository(context).GetById(userId, userId).Object;
         context.Tags.AddObject(entity);
         context.Save();
         addResponse.Id = entity.Id;
     }
     return addResponse;
 }
Ejemplo n.º 5
0
     private void FixupParent(Tag previousValue)
     {
         if (previousValue != null && previousValue.Children.Contains(this))
         {
             previousValue.Children.Remove(this);
         }
 
         if (Parent != null)
         {
             if (!Parent.Children.Contains(this))
             {
                 Parent.Children.Add(this);
             }
         }
     }