// POST api/<controller> public async Task Post(PrLinesViewModel value) { var nh = new NHibernateUserStore(); var nhps = new NHibernatePRStore(); var nhcs = new NHibernateNonCatalogStore(); var user = nh.FindByStampAsync(value.SecurityStamp); if (user != null) { var nhis = new NHibernateItemStore(); ItemModel item = null; NonCatalogItemHeadModel nonCatalog = null; if (value.itemType == "Catalog") { item = await nhis.FindItemByIdAsync(value.Id); } else { nonCatalog = await nhcs.GetNonCatalogAsync(value.Id); } var PrLines = new PRLinesModel { Item = item, NonCatalog = nonCatalog, Quantity = value.Quantity, CreatedBy = user.Result }; try { await nhps.CreatePRLinesAsync(PrLines); } catch (Exception e) { var a = e.Message; } } }
public async Task <ActionResult> POApprover() { var nh = new NHibernateUserStore(); var response = new HttpResponseMessage(HttpStatusCode.OK); var user = (UserModel)HttpContext.Session[Config.GetAppSetting("SessionKey")]; //UserModel user = null; if (user != null) { //user = (UserModel)task.GetType().GetProperty("Result").GetValue(task); } else if (CurrentUserSession.userSecurityStampCookie != null) { user = await nh.FindByStampAsync(CurrentUserSession.userSecurityStampCookie); HttpContext.Session[Config.GetAppSetting("SessionKey")] = user; var owinAuthentication = new OwinAuthenticationService(HttpContext); owinAuthentication.SignIn(user); } else { return(RedirectToAction("Login", "User")); } var nhps = new NHibernatePOStore(); var pr = await nhps.FindPOApprovalAsync(user.employee.position); return(View(pr)); }
// GET: Confirmation public async Task <ActionResult> DriverConfirmation() { string id = null; var nhs = new NHibernateUserStore(); UserModel usr = null; if (HttpContext.Session["UserId"] != null) { id = HttpContext.Session["UserId"].ToString(); } if (id == null) { usr = await nhs.FindByStampAsync(CurrentUserSession.userSecurityStampCookie); } else { usr = await nhs.FindByIdAsync(id); } ViewData["ApiServer"] = Config.GetApiServerURL(); if (usr == null || !usr.IsAdmin) { RedirectToAction("Login", "Logins"); } var hds = new NHibernateDriverStore(); var drivers = await hds.GetAllForValidationAsync(); return(View(drivers)); }
// POST api/<controller> public async Task <IList <PRApprovalViewModel> > Post(IList <PRApprovalViewModel> value) { var nh = new NHibernateUserStore(); var nhps = new NHibernatePRStore(); List <PRApprovalViewModel> PRs = new List <PRApprovalViewModel>(); foreach (var approved in value) { var user = nh.FindByStampAsync(approved.SecurityStamp); if (user != null) { var approval = await nhps.FindPRAprovalAsync(approved.Id); approval.Status = approved.Status; switch (approval.Status) { case StatusType.Approved: var PRApprovals = await nhps.FindPRAprovalAsync(approval.PRHeader); approval.ApprovedBy = user.Result; approval.DateApproved = DateTime.UtcNow; foreach (var PRApproval in PRApprovals) { if (PRApproval.Status == StatusType.Approved) { approval.PRHeader.Status = StatusType.Approved; } else { approval.PRHeader.Status = PRApproval.Status; break; } } break; case StatusType.Rejected: approval.PRHeader.Status = approval.Status; break; default: break; } try { await nhps.SaveOrUpdatePRApprovalAsync(approval); } catch (Exception e) { } approved.RequisitionNo = approval.PRHeader.RequisitionNo; PRs.Add(approved); } } return(PRs); }
// POST api/<controller> public async Task Post(CRCViewModel value) { var nhus = new NHibernateUserStore(); var nhcs = new NHibernateCompanyStore(); var CRC = new CostRevenueCenterModel { CRCCode = value.CRCCode, CRCName = value.CRCName, CreatedBy = await nhus.FindByStampAsync(value.SecurityStamp) }; await nhcs.AddCRCAsync(CRC); }
// POST api/<controller> public async Task Post(ChargeLocationViewModel value) { var nhus = new NHibernateUserStore(); var nhcs = new NHibernateCompanyStore(); var chargeLocation = new ChargeLocationModel { ChargeLocationCode = value.ChargeLocationCode, ChargeLocationName = value.ChargeLocationName, CreatedBy = await nhus.FindByStampAsync(value.SecurityStamp) }; await nhcs.AddChargeLocationAsync(chargeLocation); }
// POST api/<controller> public async Task <long> Post(POViewModel value) { const long PurchaserHead = 6; var nhpos = new NHibernatePOStore(); var nhus = new NHibernateUserStore(); var company = new NHibernateCompanyStore(); var po = await nhpos.FindPOAByIdAsync(value.Id); var user = await nhus.FindByStampAsync(value.SecurityStamp); foreach (var line in value.Lines) { var nhps = new NHibernatePRStore(); var poLine = new POLinesModel() { Quantity = line.Quantity, UOM = line.UOM, Description = line.Description, UnitPrice = line.UnitPrice, PRLine = await nhps.GetPRLineAsync(line.PRLineId), Name = line.Name, CreatedBy = user }; po.Lines.Add(poLine); } po.Status = value.Status; if (value.Status == StatusType.ForApproval) { var approver = new POAprovalModel() { Approver = await company.GetPositionByIdAsync(PurchaserHead), Status = StatusType.ForApproval }; po.Approvals = new List <POAprovalModel>(); po.Approvals.Add(approver); var costApprover = company.FindCostApprover(po.Amount); if (costApprover.Result != null) { var approver2 = new POAprovalModel() { Approver = costApprover.Result.Approver, Status = StatusType.ForApproval }; po.Approvals.Add(approver2); } } await nhpos.SaveOrUpdatePOHeaderAsync(po); return(value.Id); }
// POST api/<controller> public async Task Post(IList <PrLinesViewModel> value) { var nh = new NHibernateUserStore(); var nhps = new NHibernatePRStore(); foreach (var line in value) { var user = nh.FindByStampAsync(line.SecurityStamp); if (user != null) { await nhps.DeletePRLineAsync(line.Id); } } }
// POST api/<controller> public async Task <string> Post(RegistrationSatusModel value) { string id = null; string result = "Ok"; var nus = new NHibernateUserStore(); UserModel user = null; if (HttpContext.Current.Session["UserId"] != null) { id = HttpContext.Current.Session["UserId"].ToString(); } if (id == null) { user = await nus.FindByStampAsync(CurrentUserSession.userSecurityStampCookie); } else { user = await nus.FindByIdAsync(id); } var nds = new NHibernateDriverStore(); var driver = nds.FindByIdAsync(value.Id).Result; var existingUser = await nus.FindByNameAsync(driver.Email); driver.Status = RegistrationStatus.Accepted; driver.UpdatedBy = user; if (existingUser != null) { existingUser.Driver = driver; await nus.UpdateAsync(existingUser); } else { var usr = new UserModel { UserName = driver.Email, FirstName = driver.FirstName, LastName = driver.LastName, PasswordHash = driver.Password, SecurityStamp = Guid.NewGuid().ToString(), Driver = driver }; await nus.CreateAsync(usr); } var emails = driver.Email; await Emailer.SendMessage(driver.Email + " Activated", emails, "Registration"); return(result); }
// POST api/<controller> public async Task Post(CompanyViewModel value) { NHibernateCompanyStore nhcs = new NHibernateCompanyStore(); var nhus = new NHibernateUserStore(); var company = new CompanyModel() { CompanyCode = value.CompanyCode, CompanyName = value.CompanyName, Phone = value.Phone, Address = value.Address, Email = value.Email, Logo = value.Logo, SmallLogo = value.SmallLogo, Tin = value.Tin, CreatedBy = await nhus.FindByStampAsync(value.SecurityStamp) }; await nhcs.SaveOrUpdateCompany(company); }
// GET: PR public async Task <ActionResult> PRShop(string itemType = "Catalog") { NHibernateUserStore nh = new NHibernateUserStore(); ViewData["ApiServer"] = Config.GetApiServerURL(); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); //var task = (Task)HttpContext.Session[Config.GetAppSetting("SessionKey")]; var user = (UserModel)HttpContext.Session[Config.GetAppSetting("SessionKey")]; //UserModel user=null; if (user != null) { //user =(UserModel) task.GetType().GetProperty("Result").GetValue(task); } else if (CurrentUserSession.userSecurityStampCookie != null) { user = await nh.FindByStampAsync(CurrentUserSession.userSecurityStampCookie); HttpContext.Session[Config.GetAppSetting("SessionKey")] = user; var owinAuthentication = new OwinAuthenticationService(HttpContext); owinAuthentication.SignIn(user); } else { return(RedirectToAction("Login", "User")); } var nhps = new NHibernatePRStore(); var lines = await nhps.PRLinesCreatedAsync(user); ViewData["cartCount"] = lines.Count; ViewData["itemType"] = itemType; ViewData["ItemImagePath"] = Config.GetAppSetting("ItemImagePath"); return(View(user)); }
public async Task <ActionResult> CreatePR(IList <PrLinesViewModel> value) { List <PRLinesModel> lines = new List <PRLinesModel>(); var nhps = new NHibernatePRStore(); var nh = new NHibernateUserStore(); var nhcs = new NHibernateCompanyStore(); var user = (UserModel)HttpContext.Session[Config.GetAppSetting("SessionKey")]; //UserModel user = null; if (user != null) { //user = (UserModel)task.GetType().GetProperty("Result").GetValue(task); } else if (CurrentUserSession.userSecurityStampCookie != null) { user = await nh.FindByStampAsync(CurrentUserSession.userSecurityStampCookie); HttpContext.Session[Config.GetAppSetting("SessionKey")] = user; var owinAuthentication = new OwinAuthenticationService(HttpContext); owinAuthentication.SignIn(user); } else { return(RedirectToAction("Login", "User")); } ViewData["SmallLogo"] = Config.GetCompanyLogo(user.employee.Company.SmallLogo); ViewData["Employee"] = user.employee; ViewData["Section"] = await nhcs.TeamEmployeeAsync(user.employee.Team); foreach (var item in value) { var line = await nhps.GetPRLineAsync(item.Id); lines.Add(line); } return(PartialView(lines)); }
// POST api/<controller> public async Task <string> Post(POViewModel value) { const long PurchaserHead = 6; var nhss = new NHibernateISupplierStore(); var nhcs = new NHibernateCompanyStore(); var nhpos = new NHibernatePOStore(); var nhus = new NHibernateUserStore(); var company = new NHibernateCompanyStore(); var requierDate = value.RequiredDate < DateTime.UtcNow ? DateTime.UtcNow.AddDays(6) : value.RequiredDate; var user = await nhus.FindByStampAsync(value.SecurityStamp); var requestor = await nhcs.GetEmployeeAsync(value.RequestorId); var po = await nhpos.FindPOAByIdAsync(value.Id); if (po == null) { po = new POHeaderModel() { Supplier = await nhss.FindSupplierByIdAsync(value.SupplierId), PaymentTerm = value.PaymentTerm, Requestor = requestor, DeliveryAdress = value.DeliveryAdress, Status = value.Status, RequiredDate = requierDate, NoteToBuyer = value.NoteToBuyer, CreatedBy = user, Amount = value.Amount, CRC = requestor.Team.CRC, Lines = new List <POLinesModel>() }; foreach (var line in value.Lines) { var nhps = new NHibernatePRStore(); var poLine = new POLinesModel() { Quantity = line.Quantity, UOM = line.UOM, Description = line.Description, UnitPrice = line.UnitPrice, PRLine = await nhps.GetPRLineAsync(line.PRLineId), Name = line.Name, CreatedBy = user }; po.Lines.Add(poLine); } } else { po.Requestor = await nhcs.GetEmployeeAsync(value.RequestorId); po.DeliveryAdress = value.DeliveryAdress; po.Amount = value.Amount; for (var i = 0; i < po.Lines.Count; i++) { var found = false; var id = po.Lines.ElementAt(i).Id; foreach (var line in value.Lines) { if (line.Id == id) { found = true; po.Lines.ElementAt(i).Quantity = line.Quantity; po.Lines.ElementAt(i).UOM = line.UOM; po.Lines.ElementAt(i).Description = line.Description; po.Lines.ElementAt(i).UnitPrice = line.UnitPrice; break; } } if (found == false) { po.Lines.ElementAt(i).DeleteTime = DateTime.UtcNow; } } } if (value.Status == StatusType.ForApproval) { var approver = new POAprovalModel() { Approver = await company.GetPositionByIdAsync(PurchaserHead), Status = StatusType.ForApproval }; po.Approvals = new List <POAprovalModel>(); po.Approvals.Add(approver); var costApprover = company.FindCostApprover(po.Amount); if (costApprover.Result != null) { var approver2 = new POAprovalModel() { Approver = costApprover.Result.Approver, Status = StatusType.ForApproval }; po.Approvals.Add(approver2); } } try { await nhpos.SaveOrUpdatePOHeaderAsync(po); } catch (Exception e) { } return(po.RequisitionNo); }
public async Task <long> Post(NonCatalogViewModel value) { const long PurchaserHead = 6; var nhnch = new NHibernateNonCatalogStore(); var user = new NHibernateUserStore(); var nnc = new NHibernateNonCatalogStore(); var supplierStore = new NHibernateISupplierStore(); var subcategoryStore = new NHibernateCategoryStore(); var company = new NHibernateCompanyStore(); var createdby = await user.FindByStampAsync(value.SecurityStamp); var nonCatalog = await nnc.GetNonCatalogAsync(value.Id); if (nonCatalog == null) { nonCatalog = new NonCatalogItemHeadModel(); } nonCatalog.Name = value.Name; nonCatalog.Analysis = value.Analysis; nonCatalog.SubCategory = await subcategoryStore.FindSubCategoryByIdAsync(value.SubCategoryId); nonCatalog.Requestor = await company.GetEmployeeAsync(value.RequestorId); nonCatalog.CreatedBy = createdby; nonCatalog.Approver = await company.GetPositionByIdAsync(PurchaserHead); for (var line = 0; line < nonCatalog.Lines.Count; line++) { if (!value.Lines.Any(x => x.Id == nonCatalog.Lines.ElementAt(line).Id)) { nonCatalog.Lines.ElementAt(line).DeleteTime = DateTime.UtcNow; } } foreach (var line in value.Lines) { if (nonCatalog.Lines.Any(x => x.Id == line.Id) && line.Id != 0) { continue; } var supplier = await supplierStore.FindSupplierByIdAsync(line.SupplierId); string tempSupplier = null; if (supplier == null) { tempSupplier = line.TempSupplier; } var nonCatalogLine = new NonCatalogItemLinesModel { Selected = line.Selected, Supplier = supplier, Price = line.Price, Description = line.Description, Quantity = line.Quantity, UOM = line.UOM, Discount = line.Discount, TotalAnount = line.TotalAnount, Availability = line.Availability, Terms = line.Terms, Brand = await supplierStore.FindBrandByIdAsync(line.BrandId), CreatedBy = createdby, TempSupplier = tempSupplier }; nonCatalog.Lines.Add(nonCatalogLine); } if (value.Approved) { nonCatalog.ApprovedBy = createdby; nonCatalog.DateApproved = DateTime.UtcNow; } return(await nnc.CreateNonCatalogHeadAsync(nonCatalog)); }
// 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) { } } }