public IHttpActionResult Create([FromBody] CostDTO cost) { ThrowIfUserHasNoRole(createRole); if (cost == null) { throw new KairosException("Missing model parameter"); } if (cost.Cost_PK != 0) { throw new KairosException("Post method is not allowed because the requested primary key is must be '0' (zero) ."); } using (var costCreateHandler = new CostCreateHandler(Db, ActiveUser, new CostValidator(), new CostFactory(Db, ActiveUser), new CostQuery(Db), AccessControl)) { using (var transaction = new TransactionScope()) { var saveResult = costCreateHandler.Save(costDTO: cost, dateStamp: DateTime.Now); transaction.Complete(); if (saveResult.Success) { return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message))); } return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message))); } } }
public async Task <IActionResult> CreateCost(CostDTO costDTO) { var cost = _mapper.Map <CostDTO, Cost>(costDTO); await _costRepository.Add(cost); return(CreatedAtAction(nameof(GetCost), new { id = cost.CostId }, cost)); }
public void UpdateLastCost(int carId, decimal lastCost) { CostDTO cost = mapper.Map <Cost, CostDTO>(repo.GetAll().Where(x => x.CarId == carId).OrderByDescending(x => x.Date).First()); cost.Price = lastCost; repo.Update(mapper1.Map <CostDTO, Cost>(cost)); }
private CostEntryModel GetUpdateStateModel(int costPK) { CostEntryFormData formData = new CostEntryFormData(); List <Control> formControls = CreateFormControls(costPK); CostDTO costDTO = costQuery.GetByPrimaryKey(costPK); if (costDTO == null) { throw new KairosException($"Record with primary key '{costPK}' is not found."); } var costKategori = new CostKategoriQuery(Db).GetByPrimaryKey(costDTO.KategoriCost_FK); if (costKategori != null) { formData.CostKategoris.Add(costKategori); } return(new CostEntryModel() { FormData = formData, FormControls = formControls, Model = costDTO, }); }
public void Update(CostDTO costDTO, DateTime dateStamp) { if (costDTO == null) { throw new ArgumentNullException("Cost model is null."); } tblT_Cost cost = costFactory.CreateFromDbAndUpdateFromDTO(costDTO, dateStamp); }
public tblT_Cost Insert(CostDTO costDTO, DateTime dateStamp) { if (costDTO == null) { throw new ArgumentNullException("Cost model is null."); } tblT_Cost cost = costFactory.CreateFromDTO(costDTO, dateStamp); return(Db.tblT_Cost.Add(cost)); }
public async Task UpdateCostAsync(int id, CostDTO costDTO) { var cost = await _unitOfWork.CostRepository.GetByIdAsync(id); cost.CostType = costDTO.CostType; cost.Date = costDTO.Date; cost.Name = costDTO.Name; cost.Price = costDTO.Price; cost.UnitId = costDTO.UnitId; _unitOfWork.CostRepository.Update(cost); }
private Cost MapToCost(CostDTO cost) { return(new Cost { Id = cost.Id, Name = cost.Name, Description = cost.Description, Date = cost.Date, AccountId = Account.Id, Cash = cost.Cash }); }
public async Task <IActionResult> Add([FromRoute] string partId, [FromForm] CostDTO cost, IFormFile invoice) { await _mediator.Send(new CreateCostCommand { Amount = cost.Amount, Name = cost.Name, VatRate = cost.VatRate, PartExternalId = partId, File = invoice?.OpenReadStream(), FileName = invoice != null ? Path.GetInvalidFileNameChars().Aggregate(invoice.FileName, (currentFileName, invalidCharacter) => currentFileName.Replace(invalidCharacter.ToString(), "")) : null }); return(Ok()); }
private CostEntryModel GetCreateStateModel() { CostEntryFormData formData = new CostEntryFormData(); List <Control> formControls = CreateFormControls(0); CostDTO costDTO = new CostDTO() { Tanggal = DateTime.Now }; return(new CostEntryModel() { FormData = formData, FormControls = formControls, Model = costDTO, }); }
public async Task <IActionResult> CreateCost(int unitId) { if (!await CanUserVisitPage(unitId)) { return(RedirectToAction("AccessError", "Home")); } var costDTO = new CostDTO { UnitId = unitId, Date = DateTime.Today }; var costWithCostTypesDTO = new CostWithCostTypesDTO { CostDTO = costDTO, CostTypes = GetCostTypes(), }; return(View(costWithCostTypesDTO)); }
public SaveResult <CostEntryModel> Save(CostDTO costDTO, DateTime dateStamp) { ModelValidationResult validationResult = costValidator.Validate(costDTO); bool success = false; CostEntryModel model = null; if (validationResult.IsValid) { success = true; Update(costDTO, dateStamp); Db.SaveChanges(); model = costEntryDataProvider.Get(costDTO.Cost_PK); } return(new SaveResult <CostEntryModel> { Success = success, Message = validationResult.IsValid ? "Data successfully updated." : "Validation error occured.", Model = model, ValidationResult = validationResult }); }
public async Task <IActionResult> UpdateCost(int id, CostDTO costDTO) { if (id != costDTO.CostId) { return(BadRequest()); } try { var cost = _mapper.Map <CostDTO, Cost>(costDTO); await _costRepository.Update(id, cost); } catch (DbUpdateConcurrencyException) { if (!await CostExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task UpdateCostAsync(int id, CostDTO costDTO) { await _costService.UpdateCostAsync(id, costDTO); await _unitOfWork.CommitAsync(); }
public CostDTO GetByPrimaryKey(int primaryKey) { CostDTO record = GetQuery().FirstOrDefault(cost => cost.Cost_PK == primaryKey); return(record); }
public void AddCost(CostDTO cost) { throw new NotImplementedException(); }