public ResultHelper AddSubUnit(SubUnitDto subUnitDto) { try { if (IsThere(subUnitDto)) { return(new ResultHelper(false, subUnitDto.SubUnitID, ResultHelper.IsThereItem)); } subunit item = new subunit(); item.SubUnitID = subUnitDto.SubUnitID; item.MainUnitID = subUnitDto.MainUnitID; item.Name = subUnitDto.Name; using (UnitOfWork unitofWork = new UnitOfWork()) { unitofWork.GetRepository <subunit>().Insert(item); unitofWork.saveChanges(); return(new ResultHelper(true, item.SubUnitID, ResultHelper.SuccessMessage)); } } catch (Exception ex) { return(new ResultHelper(false, subUnitDto.SubUnitID, ResultHelper.UnSuccessMessage)); } }
public SubUnitDto GetSubUnit(int subUnitID) { try { using (UnitOfWork unitofWork = new UnitOfWork()) { subunit item = new subunit(); item = unitofWork.GetRepository <subunit>().GetById(x => x.SubUnitID == subUnitID); SubUnitDto subUnitDto = new SubUnitDto(); subUnitDto.SubUnitID = item.SubUnitID; subUnitDto.Name = item.Name; subUnitDto.MainUnitID = (int)item.MainUnitID; return(subUnitDto); } } catch (Exception) { return(null); } }