public OpResult SaveOrUpdate(DeviceAuthorize obj, string category, string brand, string spec) { //if (!TraderRepository.GetQuery(o => o.CID == obj.CID).Any()) //return OpResult.Fail("商户不存在!"); if (category.IsNullOrEmpty() || brand.IsNullOrEmpty() || spec.IsNullOrEmpty()) { return(OpResult.Fail("设备分类等信息选择不完整!")); } var cate = short.Parse(category); var device = DevicesRepository.Find(o => o.CategoryId == cate && o.Brand == brand && o.Spec == spec); if (device == null) { return(OpResult.Fail("设备分类不存在,请重新选择!")); } obj.DeviceId = device.DeviceId; if (DeviceAuthorRepository.GetQuery(o => o.DeviceId == obj.DeviceId && o.DeviceNo == obj.DeviceNo && o.Status != 2 && o.Id != obj.Id).Any()) { return(OpResult.Fail("同设备和编码下不允许重复添加!")); } if (obj.Id == 0) { obj.CreateDT = DateTime.Now; obj.CreateUID = CurrentUser.UID; obj.ExpirationDT = DateTime.Parse(obj.EffectiveDT).AddMonths(obj.ValidityNum.GetValueOrDefault()).ToString("yyyy-MM-dd"); DeviceAuthorRepository.Add(obj); } else { var res = DeviceAuthorRepository.Get(obj.Id); obj.ToCopyProperty(res, new List <string>() { "CreateDT", "CreateUID", "CID", "MachineSN", "SerialNo" }); res.ExpirationDT = DateTime.Parse(obj.EffectiveDT).AddMonths(obj.ValidityNum.GetValueOrDefault()).ToString("yyyy-MM-dd"); DeviceAuthorRepository.SaveChanges(); } return(OpResult.Success()); }
public DeviceAuthorize GetOne(object id) { var obj = DeviceAuthorRepository.Get(id); return(obj); }