private List <Tag> ExtractNewTags(AddEditFinOperationDto model) { return (model.Tags. Where(tag => !tag.Id.HasValue) .Select(tagDto => tagDto.ToTag(model.UserId)) .ToList()); }
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 }); }
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(); }
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(); }
public CustomJsonResult Edit(AddEditFinOperationDto model) { model.UserId = this.Session.GetCurrentUserId(); this.finOperationService.Edit(model); return(this.SuccessResult()); }