public async Task <InvoiceCategoryDto> SaveAsync(Guid orgId, InvoiceCategoryDto dto) { if (orgId == null || orgId == Guid.Empty) { throw new ArgumentNullException("orgId", "Org id is missing"); } InvoiceCategory category = _mapper.Map <InvoiceCategory>(dto); if (category.Id == Guid.Empty) { category.OrgId = orgId; category.DateCreated = DateTime.UtcNow; category.DateModified = null; await _context.InvoiceCategories.AddAsync(category); } else { category.OrgId = orgId; category.DateModified = DateTime.UtcNow; _context.InvoiceCategories.Update(category); } await _context.SaveChangesAsync(); dto = _mapper.Map <InvoiceCategoryDto>(category); return(dto); }
public InvoiceDataGrid(Invoice invoice) { this.BuildingId = invoice.BuildingId; this.ContractorName = invoice.ContractorName; this.CostAmount = invoice.CostAmount; this.CreatedTime = invoice.CreatedTime; this.InvoiceCategoryId = invoice.InvoiceCategoryId; this.InvoiceDate = invoice.InvoiceDate; this.InvoiceCreatedDate = invoice.InvoiceCreatedDate; this.InvoiceId = invoice.InvoiceId; this.InvoiceNumber = invoice.InvoiceNumber; this.IsDeleted = invoice.IsDeleted; this.IsSettled = invoice.IsSettled; this.Title = invoice.Title; this.CostAmountGross = invoice.CostAmountGross; this.CostAmountConst = invoice.CostAmountConst; this.CostAmountConstGross = invoice.CostAmountConstGross; this.VariableVat = invoice.VariableVat; this.CostAmountVariable = invoice.CostAmountVariable; this.CostAmountVariableGross = invoice.CostAmountVariableGross; this.ConstVat = invoice.ConstVat; using (var db = new DB.DomenaDBContext()) { this.Building = db.Buildings.Where(x => x.BuildingId.Equals(invoice.BuildingId)).FirstOrDefault(); this.Category = db.InvoiceCategories.Where(x => x.CategoryId.Equals(invoice.InvoiceCategoryId)).FirstOrDefault(); } }
public async Task <bool> DeleteAsync(Guid id) { InvoiceCategory category = await _context.InvoiceCategories .FindAsync(id); if (category != null) { _context.InvoiceCategories.Remove(category); await _context.SaveChangesAsync(); return(true); } throw new KeyNotFoundException("Invoice category not found"); }
private void AddCategory(object param) { if (string.IsNullOrWhiteSpace(CategoryName)) { LabelError = "Błędna nazwa"; return; } var ic = new InvoiceCategory { CategoryName = CategoryName, CategoryId = Guid.NewGuid(), IsDeleted = false }; CategoryCollection.Add(ic); commandBuffer.Add(new Helpers.CategoryCommand <InvoiceCategory> { CommandType = Helpers.CommandEnum.Add, Item = ic }); }