示例#1
0
        public async Task <IHttpActionResult> Put(string id, MdContractVm.Dto instance)
        {
            var result = new TransferObj <MdContract>();

            if (id != instance.Id)
            {
                result.Status  = false;
                result.Message = "Id không hợp lệ";
                return(Ok(result));
            }

            try
            {
                var item = _service.UpdateDto(instance);
                _service.UnitOfWork.Save();
                result.Status = true;
                result.Data   = item;
                return(Ok(result));
            }
            catch (Exception e)
            {
                result.Status  = false;
                result.Message = e.Message;
                return(Ok(result));
            }
        }
示例#2
0
        public TransferObj <MdContractVm.Dto> GetDetails(string id)
        {
            var result         = new TransferObj <MdContractVm.Dto>();
            var temp           = new MdContractVm.Dto();
            var hopDong        = _service.FindById(id);
            var chitietHopDong = _service.UnitOfWork.Repository <MdDetailContract>().DbSet;

            if (hopDong != null)
            {
                temp = Mapper.Map <MdContract, MdContractVm.Dto>(hopDong);
                var chiTietHopDong = chitietHopDong.Where(x => x.MaHd == hopDong.MaHd).ToList();
                temp.DataDetails = Mapper.Map <List <MdDetailContract>, List <MdContractVm.Detail> >(chiTietHopDong);
                result.Data      = temp;
                result.Status    = true;
            }
            return(result);
        }
示例#3
0
        public async Task <IHttpActionResult> Post(MdContractVm.Dto instance)
        {
            var result = new TransferObj <MdContract>();

            try
            {
                var item = _service.InsertDto(instance);
                _service.UnitOfWork.Save();
                result.Status = true;
                result.Data   = item;
            }
            catch (Exception e)
            {
                result.Status  = false;
                result.Message = e.Message;
                return(Ok(result));
            }
            return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result));
        }