public async Task <IList <PRAprovalModel> > FindPRAprovalAsync(PRHeaderModel pr) { using (var db = HibernateSession.GetCurrentSession()) { using (var tx = db.BeginTransaction()) { return(db.QueryOver <PRAprovalModel>().Where(x => x.PRHeader == pr).List()); } } }
public async Task CreatePRHeaderAsync(PRHeaderModel header) { using (var db = HibernateSession.GetCurrentSession()) { using (var tx = db.BeginTransaction()) { db.Save(header); var pra = new PRAccessor(); header.RequisitionNo = pra.GetRequisitionNo(header.Requestor, header.Id); db.Update(header); tx.Commit(); db.Flush(); } } }
public async Task <ActionResult> POCreation(IList <PrLinesViewModel> value) { var nhpa = new NHibernatePRStore(); PRHeaderModel PR = null; var prLines = new List <PRLinesModel>(); foreach (var line in value) { var prLine = await nhpa.GetPRLineAsync(line.Id); prLines.Add(prLine); if (PR == null) { PR = prLine.Header; } } ViewData["PR"] = PR; return(PartialView(prLines)); }
public async Task <IList <PRHeaderModel> > SearchPRAsync(string search) { using (var db = HibernateSession.GetCurrentSession()) { using (var tx = db.BeginTransaction()) { //var items = db.QueryOver<PRHeaderModel>().Where((Restrictions.On<PRHeaderModel>(x => x.RequisitionNo).IsLike(search + "%") // //|| Restrictions.On<PRHeaderModel>(x => x.Requestor.LastName).IsLike(search + "%") // /*|| Restrictions.On<PRHeaderModel>(x => x.Requestor.Department.Name).IsLike(search + "%")*/) // && Restrictions.On<PRHeaderModel>(x => x.DeleteTime).IsNull).JoinQueryOver<EmployeeModel>(c=>c.Requestor).Where(Restrictions.On<EmployeeModel>(k=>k.Name()).IsLike(search + "%")); PRHeaderModel pr = null; EmployeeModel emp = null; DepartmentModel dep = null; var items = db.QueryOver <PRHeaderModel>(() => pr) .JoinAlias(() => pr.Requestor, () => emp) .JoinAlias(() => emp.Department, () => dep) .Where(x => pr.DeleteTime == null && pr.Status == StatusType.Approved && (pr.RequisitionNo.IsLike("%" + search + "%") || emp.LastName.IsLike(search + "%") || dep.Name.IsLike(search + "%"))).OrderBy(() => pr.CreateTime).Desc.Take(10); return(items.List()); } } }
// POST api/<controller> public async Task Post(PRViewModel value) { var nh = new NHibernateUserStore(); var nhps = new NHibernatePRStore(); var session = HttpContext.Current.Session; //var sessionKey = Config.GetAppSetting("SessionKey").ToString(); var user = nh.FindByStampAsync(value.SecurityStamp); if (user != null) { var nhcs = new NHibernateCompanyStore(); var utcDate = value.DateNeeded.ToUniversalTime(); var requestor = await nhcs.GetEmployeeAsync(value.RequestorId); DateTime dateNeeded; if (value.DateNeeded < DateTime.UtcNow) { dateNeeded = DateTime.UtcNow.AddDays(6); } else { dateNeeded = value.DateNeeded; } var prHeader = new PRHeaderModel() { Status = StatusType.Request, Requestor = requestor, DeliveryAdress = value.DeliveryAdress, NoteToBuyer = value.NoteToBuyer, DateNeeded = dateNeeded, CRC = requestor.Team.CRC, CreatedBy = user.Result, Lines = new List <PRLinesModel>(), Approvals = new List <PRAprovalModel>(), }; if (requestor.ImmediateLeader != null) { var immedieateAprover = new PRAprovalModel() { Approver = requestor.ImmediateLeader, Status = StatusType.Request, CreatedBy = user.Result }; prHeader.Approvals.Add(immedieateAprover); } if (requestor.Department != null) { if (!prHeader.Approvals.Any(s => s.Approver.Id == requestor.Department.DepartmentLeader.Id)) { var DepLeadAproval = new PRAprovalModel() { Approver = requestor.Department.DepartmentLeader, Status = StatusType.Request, CreatedBy = user.Result }; prHeader.Approvals.Add(DepLeadAproval); } } if (requestor.Company.Corfin != null && requestor.Company.Corfin.Id != requestor.position.Id) { if (!prHeader.Approvals.Any(s => s.Approver.Id == requestor.Company.Corfin.Id)) { var corfin = new PRAprovalModel() { Approver = requestor.Company.Corfin, Status = StatusType.Request, CreatedBy = user.Result }; prHeader.Approvals.Add(corfin); } } foreach (var line in value.Lines) { var lin = await nhps.GetPRLineAsync(line.Id); if (lin.Item != null) { if (lin.Item.SubCategory != null) { if (!prHeader.Approvals.Any(s => s.Approver.Id == lin.Item.SubCategory.Category.Approver.Id)) { var ItemAproval = new PRAprovalModel() { Approver = lin.Item.SubCategory.Category.Approver, Status = StatusType.Request, CreatedBy = user.Result }; prHeader.Approvals.Add(ItemAproval); } } lin.Description = lin.Item.Description; lin.Supplier = lin.Item.Supplier; lin.UnitPrice = lin.Item.Price; lin.UOM = lin.Item.UOM; } else { if (lin.NonCatalog.SubCategory != null) { if (!prHeader.Approvals.Any(s => s.Approver.Id == lin.NonCatalog.SubCategory.Category.Approver.Id)) { var ItemAproval = new PRAprovalModel() { Approver = lin.NonCatalog.SubCategory.Category.Approver, Status = StatusType.Request, CreatedBy = user.Result }; prHeader.Approvals.Add(ItemAproval); } } var item = lin.NonCatalog.Lines.Where(x => x.Selected == true && x.DeleteTime == null).SingleOrDefault(); lin.Description = item.Description; lin.Supplier = item.Supplier; lin.UnitPrice = item.Price; lin.UOM = item.UOM; } lin.TotalAmount = lin.Quantity * lin.UnitPrice; prHeader.Amount += lin.TotalAmount; prHeader.Lines.Add(lin); } try { await nhps.CreatePRHeaderAsync(prHeader); } catch (Exception e) { } } }