Example #1
0
 private List <Tag> ExtractNewTags(AddEditFinOperationDto model)
 {
     return
         (model.Tags.
          Where(tag => !tag.Id.HasValue)
          .Select(tagDto => tagDto.ToTag(model.UserId))
          .ToList());
 }
Example #2
0
 public static FinancialOperation ToFinancialOperation(this AddEditFinOperationDto dto)
 {
     return(new FinancialOperation
     {
         UserId = dto.UserId,
         CategoryId = dto.CategoryId,
         Type = dto.Type,
         Description = dto.Description,
         Date = dto.Date,
         Value = dto.Value
     });
 }
Example #3
0
        public void Add(AddEditFinOperationDto model)
        {
            FinancialOperation finOperation = model.ToFinancialOperation();

            List <Tag> tags = this.ExtractNewTags(model);

            tags.AddRange(this.ExtractExistingTags(model.Tags));

            finOperation.Tags = tags;

            this.repository.AddRange(finOperation.Clone(model.Amount));
            this.repository.SaveChanges();
        }
Example #4
0
        public void Edit(AddEditFinOperationDto model)
        {
            var targetFinOperation = this.repository.FindById <FinancialOperation>(model.Id);

            targetFinOperation.Value       = model.Value;
            targetFinOperation.Date        = model.Date;
            targetFinOperation.Description = model.Description;
            targetFinOperation.CategoryId  = model.CategoryId;

            targetFinOperation.Tags.Clear();

            List <Tag> tags = this.ExtractNewTags(model);

            tags.AddRange(this.ExtractExistingTags(model.Tags));

            foreach (Tag tag in tags)
            {
                targetFinOperation.Tags.Add(tag);
            }

            this.repository.SaveChanges();
        }
Example #5
0
 public CustomJsonResult Edit(AddEditFinOperationDto model)
 {
     model.UserId = this.Session.GetCurrentUserId();
     this.finOperationService.Edit(model);
     return(this.SuccessResult());
 }