/// <summary> /// Delete expense record from datase /// </summary> /// <param name="userId">User identifier</param> /// <param name="entity">Expense record identifier</param> /// <returns>Execution result</returns> public Response Delete(int userId, ExpenseRecord entity) { var response = new Response(); if (HasUserAccess(userId, entity.Id)) { context.ExpenseRecords.DeleteObject(entity); context.Save(); } else { response.IsError = true; response.Errors.Add(Error.UserDoesNotHaveAccess); } return response; }
/// <summary> /// Method updates the expense record /// </summary> /// <param name="userId">User identifier</param> /// <param name="expenseRecordId">Expense record identifier. By this identifier we will find record for changing</param> /// <param name="description">Description for expense record</param> /// <param name="price">Price</param> /// <param name="tagId">Tag identifier for expense record</param> /// <param name="dateStamp">Date stamp which shows when money were spent</param> /// <returns></returns> public Response Edit(int userId, int expenseRecordId, string description, decimal price, int tagId, DateTime? dateStamp) { var response = new Response(); if (HasUserAccess(userId, expenseRecordId)) { if (string.IsNullOrEmpty(description) || price == 0 || tagId == 0 || dateStamp == null) { response.IsError = true; response.Errors.Add(Error.ExpenseRecordHasNotBeenSet); } else { var expenseRecord = GetById(userId, expenseRecordId).Object; var tagRepository = new TagRepository(context); expenseRecord.Tag = tagRepository.GetById(userId, tagId).Object; expenseRecord.Description = description; expenseRecord.Price = price; expenseRecord.DateStamp = (DateTime)dateStamp; context.Save(); } } else { response.IsError = true; response.Errors.Add(Error.UserDoesNotHaveAccess); } return response; }
/// <summary> /// Method deletes expense record from the system /// </summary> /// <param name="userId">User identifier</param> /// <param name="expenseRecordId">Expense record identifier. By this identifier we will delete record from the system</param> /// <returns>Executin result as Response object</returns> public Response Delete(int userId, int expenseRecordId) { var response = new Response(); if (HasUserAccess(userId, expenseRecordId)) { Delete(userId, GetById(userId, expenseRecordId).Object); } else { response.IsError = true; response.Errors.Add(Error.UserDoesNotHaveAccess); } return response; }
/// <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; }
/// <summary> /// Deletes tag from the system /// </summary> /// <param name="userId">User identifier</param> /// <param name="tagId">Tag identifier</param> /// <returns>Execution result</returns> public Response DeleteById(int userId, int tagId) { var response = new Response(); if (HasUserAccess(userId, tagId)) { var tag = context.Tags.Where(a => a.Id == tagId).FirstOrDefault(); if (tag == null) { response.IsError = true; response.Errors.Add(Error.TagHasNotBeenSelected); } else { Delete(userId, tag); context.Save(); } } else { response.IsError = true; response.Errors.Add(Error.UserDoesNotHaveAccess); } return response; }
/// <summary> /// Changes tag name /// </summary> /// <param name="userId">User identifier</param> /// <param name="tagId">Tag identifier</param> /// <param name="tagName">Tag name</param> /// <returns>Execution result of changing name</returns> public Response ChangeTagName(int userId, int tagId, string tagName) { var response = new Response(); if (HasUserAccess(userId, tagId)) { if (string.IsNullOrEmpty(tagName)) { response.IsError = true; response.Errors.Add(Error.TagNameHasNotBeenSet); } else { var tag = GetById(userId, tagId).Object; tag.Name = tagName; context.Save(); } } else { response.IsError = true; response.Errors.Add(Error.UserDoesNotHaveAccess); } return response; }
/// <summary> /// Delete entity from datase /// </summary> /// <param name="userId">User identifier</param> /// <param name="entity">Entity identifier</param> /// <returns>Execution result</returns> public Response Delete(int userId, User entity) { var response = new Response(); context.Users.DeleteObject(entity); context.Save(); return response; }