public List <IQueryFilter> GetFilters() { var result = new List <IQueryFilter>(); var refObj = new MdPackaging(); if (!string.IsNullOrEmpty(this.MaBaoBi))//MaTk { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.MaBaoBi), Value = this.MaBaoBi, Method = FilterMethod.Like }); } if (!string.IsNullOrEmpty(this.TenBaoBi)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.TenBaoBi), Value = this.TenBaoBi, Method = FilterMethod.Like }); } return(result); }
public async Task <IHttpActionResult> Delete(string id) { MdPackaging instance = await _service.Repository.FindAsync(id); if (instance == null) { return(NotFound()); } try { _service.Delete(instance.Id); await _service.UnitOfWork.SaveAsync(); return(Ok(instance)); } catch (Exception) { return(InternalServerError()); } }
public async Task <IHttpActionResult> Post(MdPackaging instance) { var result = new TransferObj <MdPackaging>(); try { instance.ICreateBy = _service.GetClaimsPrincipal().Identity.Name; instance.ICreateDate = DateTime.Now; var item = _service.Insert(instance); _service.UnitOfWork.Save(); result.Status = true; result.Message = "Thêm mới thành công"; 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)); }
public async Task <IHttpActionResult> Put(string id, MdPackaging instance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != instance.Id) { return(BadRequest()); } var result = new TransferObj <MdPackaging>(); if (id != instance.Id) { result.Status = false; result.Message = "Id không hợp lệ"; return(Ok(result)); } try { instance.IUpdateBy = _service.GetClaimsPrincipal().Identity.Name; instance.IUpdateDate = DateTime.Now; var item = _service.Update(instance); _service.UnitOfWork.Save(); result.Status = true; result.Data = item; result.Message = "Cập nhật thành công"; return(Ok(result)); } catch (Exception e) { result.Status = false; result.Message = e.Message; return(Ok(result)); } }