public WorkerInfo Get(string WorkerID) { db.Open(); WorkerClientList clientListObj = new WorkerClientList(); WorkerSkill WorkerSkill = new WorkerSkill(); WorkerAdjustment WorkerAdjustment = new WorkerAdjustment(); WorkerAttachment WorkerAttachment = new WorkerAttachment(); string query = "select * from Worker " + " where WorkerID = @WorkerID "; try { var obj = (List <WorkerInfo>)db.Query <WorkerInfo>(query, new { WorkerID = WorkerID }); WorkerInfo info; if (obj.Count > 0) { info = obj[0]; info.ClientList = clientListObj.Get(WorkerID); info.SkillList = WorkerSkill.GetSkillList(WorkerID); info.AdjustmentList = WorkerAdjustment.GetList(WorkerID); info.AttachmentList = WorkerAttachment.GetList(WorkerID); return(info); } else { return(null); } } finally { db.Close(); } }
public string Save(WorkerInfo info) { this.db.Open(); this.transaction = this.db.BeginTransaction(); try { if (this.IsExisted(info)) { this.Update(info); } else { this.Insert(info); } WorkerClientList clientListObj = new WorkerClientList(this.db, this.transaction); clientListObj.Save(info.ClientList, info.WorkerID); int rowno = 0; WorkerSkill WorkerSkill = new WorkerSkill(this.db, this.transaction); if (info.SkillList != null) { foreach (WorkerSkillInfo skill in info.SkillList) { skill.WorkerID = info.WorkerID; skill.RowNo = ++rowno; WorkerSkill.Save(skill); } } WorkerSkill.Delete(info.WorkerID, ++rowno); WorkerAdjustment WorkerAdjustment = new WorkerAdjustment(this.db, this.transaction); rowno = 0; if (info.AdjustmentList != null) { foreach (WorkerAdjustmentInfo adjust in info.AdjustmentList) { adjust.WorkerID = info.WorkerID; adjust.RowNo = ++rowno; WorkerAdjustment.Save(adjust); } } WorkerAdjustment.Delete(info.WorkerID, ++rowno); WorkerAttachment WorkerAttachment = new WorkerAttachment(this.db, this.transaction); rowno = 0; List <int> existingRowNo = new List <int>(); if (info.AttachmentList != null) { foreach (WorkerAttachmentInfo adjust in info.AttachmentList) { existingRowNo.Add(adjust.RowNo); adjust.WorkerID = info.WorkerID; WorkerAttachment.Save(adjust); } } WorkerAttachment.Delete(info.WorkerID, existingRowNo); this.transaction.Commit(); } catch { this.transaction.Rollback(); throw; } finally { this.db.Close(); } return(info.WorkerID); }