private void SetupModels() { _conrtactId = 1; _contactServiceModel = new ContractServiceModel { Id = _conrtactId, CustomerId = 1, Date = It.IsAny <DateTime>(), Tarif = "postpejd", WorkerId = 1 }; _contractControllerModel = new ContractControllerModel { Id = _contactServiceModel.Id, CustomerId = _contactServiceModel.CustomerId, Tarif = _contactServiceModel.Tarif, WorkerId = _contactServiceModel.WorkerId }; _contractSreviceModelList = new List <ContractServiceModel> { new ContractServiceModel { Id = 1, CustomerId = 1, WorkerId = 1, Date = DateTime.Now, Tarif = "pripejd" }, new ContractServiceModel { Id = 2, CustomerId = 2, WorkerId = 2, Date = DateTime.Now, Tarif = "pripejd" } }; _custumerControllerModelList = new List <ContractControllerModel> { new ContractControllerModel { Id = 1, CustomerId = 1, WorkerId = 1, Tarif = "pripejd" }, new ContractControllerModel { Id = 1, CustomerId = 1, WorkerId = 1, Tarif = "pripejd" } }; }
public IActionResult PostContract([FromBody] ContractControllerModel contract) { try { log.Info("Reached PostContract([FromBody] ContractControllerModel contract) in ContractsController.cs"); if (!ModelState.IsValid) { log.Error("A ModelState isn't valid error occured in PostContract([FromBody] ContractControllerModel contract) in ContractsController.cs"); return(BadRequest(ModelState)); } service.Add(mapper.Map <ContractServiceModel>(contract)); log.Info("Added new Contract object in PostContract([FromBody] ContractControllerModel contract) in ContractsController.cs"); return(Ok(contract)); } catch (Exception e) { log.Error(string.Format("An exception {0} occured in PostContract([FromBody] ContractControllerModel contract) in ContractsController.cs", e)); return(NotFound()); } }
public IActionResult PutContract(int id, ContractControllerModel contract) { try { log.Info("Reached PutContract(int id, ContractControllerModel contract) in ContractsController.cs"); if (!ModelState.IsValid) { log.Error("A ModelState isn't valid error occured in PutContract(int id, [FromBody] ContractControllerModel contract) in ContractsController.cs"); return(BadRequest()); } if (id != contract.Id) { log.Error("Contract object isn't matched with given id! Error occured in PutContract(int id, ContractControllerModel contract) in ContractsController.cs"); return(NotFound()); } bool exists = service.Update(mapper.Map <ContractServiceModel>(contract)); if (exists) { log.Info("Modified Contract object in PutContract(int id, ContractControllerModel contract) in ContractsController.cs"); return(Ok()); } log.Error("Contract object with given id doesn't exist! Error occured in PutContract(int id, ContractControllerModel contract) in ContractsController.cs"); return(NotFound()); } catch (Exception e) { log.Error(string.Format("An exception {0} occured in PutContract(int id, ContractControllerModel contract) in ContractsController.cs", e)); return(StatusCode(500)); } }
public IActionResult GetContract(int id) { try { log.Info("Reached GetContract(int id) in ContractsController.cs"); ContractControllerModel contract = mapper.Map <ContractControllerModel>(service.Get(id)); if (contract == null) { log.Error("Got null object in GetContract(int id) in ContractsController.cs"); return(NotFound("Contract not found")); } log.Info("Returned Contract object from GetContract(int id) in ContractsController.cs"); return(Ok(contract)); } catch (Exception e) { log.Error(string.Format("An exception {0} occured in GetContract() in ContractsController.cs", e)); return(StatusCode(500)); } }