private bool IsExist(LabDetailModel model) { try { Expression <Func <LabDetail, bool> > predicate = null; using (var db = new HMSEntities()) { /* Build Predicate according to Create or Update */ if (!model.Id.HasValue) { predicate = o => o.Name == model.Name && o.IsActive == true && o.IsDeleted == false;//for Create Record } else { predicate = o => o.Name == model.Name && o.Id != model.Id && o.IsActive == true && o.IsDeleted == false;//for Update Record Record } /* return is Exist or not */ if (db.LabDetails.Any(predicate)) { return(true); } else { return(false); } } } catch (Exception ex) { throw ex; } }
private void FillFormData(Guid?id) { try { LabDetailModel model = service.GetById(id.Value); if (model != null) { LabDetailOperations frm = new LabDetailOperations(model.Id); frm.txtFullName.Text = model.Name; frm.txtAddress.Text = model.Address; frm.txtPathalogist.Text = model.PathelogistName; frm.txtPhoneNumber.Text = model.PhoneNumber; frm.chkInHouse.Checked = model.IsInHouse.HasValue ? model.IsInHouse.Value : false; frm.ShowDialog(); if (isSubmited) { Search(); } isSubmited = false; } } catch (Exception ex) { isSubmited = false; Utility.ErrorLog.Logging("Lab List", ex.Message.ToString(), ex.StackTrace.ToString()); } }
public LabDetailModel GetById(Guid id) { try { LabDetailModel model = new LabDetailModel(); using (var db = new HMSEntities()) { LabDetail entity = db.LabDetails.Find(id); if (entity != null) { model.Id = entity.Id; model.Name = entity.Name; model.PathelogistName = entity.PathelogistName; model.Address = entity.Address; model.PhoneNumber = entity.PhoneNumber; model.IsInHouse = entity.IsInHouse; model.IsActive = entity.IsActive; model.IsDeleted = entity.IsDeleted; model.CreatedOn = entity.CreatedOn; model.CreatedBy = entity.CreatedBy; model.ModifiedOn = entity.ModifiedOn; model.ModifiedBy = entity.ModifiedBy; } } return(model); } catch (Exception ex) { throw ex; } }
public bool Update(LabDetailModel model) { try { bool isSaved = false; if (!IsExist(model)) { using (var db = new HMSEntities()) { //UpdateAllSequence(model.Id, model.Sequence.Value, model.PerentId); LabDetail entity = db.LabDetails.Find(model.Id); entity.Name = model.Name; entity.PathelogistName = model.PathelogistName; entity.Address = model.Address; entity.PhoneNumber = model.PhoneNumber; entity.IsInHouse = model.IsInHouse.HasValue ? model.IsInHouse.Value : false; entity.ModifiedOn = DateTime.Now; entity.ModifiedBy = UserDetailSession.Id; db.SaveChanges(); isSaved = true; } } return(isSaved); } catch (Exception ex) { throw ex; } }
public LabDetailModel GetByName(string name) { try { LabDetailModel model = new LabDetailModel(); using (var db = new HMSEntities()) { LabDetail entity = db.LabDetails.FirstOrDefault(t => t.Name == name); if (entity != null) { model.Id = entity.Id; model.Name = entity.Name; model.PathelogistName = entity.PathelogistName; model.Address = entity.Address; model.PhoneNumber = entity.PhoneNumber; model.IsActive = entity.IsActive; model.IsDeleted = entity.IsDeleted; model.CreatedOn = entity.CreatedOn; model.CreatedBy = entity.CreatedBy; model.ModifiedOn = entity.ModifiedOn; model.ModifiedBy = entity.ModifiedBy; } } return(model); } catch (Exception ex) { throw ex; } }
private bool saveData() { try { LabDetailModel model = assignModel(); if (model != null) { if (this.currentUserId.HasValue) { return(service.Update(model)); } else { return(service.Create(model)); } } else { return(false); } } catch (Exception ex) { ErrorLog.Logging("Lab Details", ex.Message.ToString(), ex.StackTrace.ToString()); return(false); } }
public bool Update(LabDetailModel model) { try { LabDetail entity = new LabDetail(); return(entity.Update(model)); } catch (Exception ex) { throw ex; } }
private LabDetailModel assignModel() { LabDetailModel model = new LabDetailModel(); try { model.Id = this.currentUserId; model.Name = txtFullName.Text; model.PathelogistName = txtPathalogist.Text; model.PhoneNumber = txtPhoneNumber.Text; model.Address = txtAddress.Text; model.IsInHouse = chkInHouse.Checked; return(model); } catch (Exception ex) { ErrorLog.Logging("Lab Details", ex.Message.ToString(), ex.StackTrace.ToString()); return(null); } }
public bool Create(LabDetailModel model) { try { bool isSaved = false; if (!IsExist(model)) { using (var db = new HMSEntities()) { LabDetail entity = new LabDetail(); entity.Name = model.Name; entity.PathelogistName = model.PathelogistName; entity.Address = model.Address; entity.PhoneNumber = model.PhoneNumber; entity.IsInHouse = model.IsInHouse.HasValue ? model.IsInHouse.Value : false; entity.IsActive = true; entity.IsDeleted = false; entity.CreatedOn = DateTime.Now; entity.CreatedBy = UserDetailSession.Id; db.LabDetails.Add(entity); db.SaveChanges(); isSaved = true; } } return(isSaved); } catch (Exception ex) { throw ex; } }