/// <summary> /// Christian Lopez /// Created: 2017/03/08 /// /// Adds Agreed Products. /// </summary> /// <param name="supplierUser"></param> private void addAgreedProducts(User supplierUser) { foreach (Product p in _agreedProducts) { try { if (_type.Equals("Adding")) { _agreementManager.CreateAgreementsForSupplier(_supplierManager.RetrieveSupplierByUserId(supplierUser.UserId), p, _currentUser.UserId); } else if (_type.Equals("Applying")) { _agreementManager.CreateAgreementsForSupplier(_supplierManager.RetrieveSupplierByUserId(supplierUser.UserId), p); } } catch (Exception ex) { throw new ApplicationException("Could not store " + p.Name + " as an agreement. Error: " + ex.Message, ex.InnerException); } } }
/// <summary> /// Ethan Jorgensen /// /// Created: /// 2017/04/29 /// /// GET: /SupplierGoods/ /// </summary> /// <returns></returns> public ActionResult Index() { var userId = usrMgr.RetrieveUserByUserName(User.Identity.GetUserName()).UserId; Supplier sup; try { sup = supMgr.RetrieveSupplierByUserId(userId); Debug.WriteLine("Supplier fetched: here's some pointless data about it " + sup.FarmTaxID); } catch { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (sup == null) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } foreach (SupplierProductLot whatever in plMgr.RetrieveSupplierProductLotsBySupplier(sup)) { Debug.WriteLine(whatever.ProductName + " " + whatever.Price); } return(View(plMgr.RetrieveSupplierProductLotsBySupplier(sup))); }
public ActionResult Index() { List <CompanyOrderWithLines> orders; try { DataObjects.User usr = _userManager.RetrieveUserByUserName(User.Identity.Name); Supplier supplier = _supplierManager.RetrieveSupplierByUserId(usr.UserId); //orders = _companyOrderManager.RetrieveCompanyOrdersWithLines(); orders = _companyOrderManager.RetrieveCompanyOrdersWithLinesBySupplierId(supplier.SupplierID); return(View(orders)); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } }
//public ActionResult Create([Bind(Include = "FarmTaxID,UserId,FarmName,FarmAddress,FarmCity,FarmState,Agreements")] SupplierWithAgreements supplierWithAgreements) public async Task <ActionResult> Create([Bind(Include = "FirstName,LastName,Phone,AddressLineOne,AddressLineTwo,City,State,Zip,EmailAddress,UserName,Password,ConfirmPassword,FarmTaxID,FarmName,FarmAddress,FarmCity,FarmState,ProductIDs")] SupplierApplicantViewModel supplierApplicant) { supplierApplicant.Agreements = new List <AgreementWithProductName>(); if (supplierApplicant.ProductIDs != null) { for (int i = 0; i < supplierApplicant.ProductIDs.Length; i++) { supplierApplicant.Agreements.Add(new AgreementWithProductName() { ProductId = supplierApplicant.ProductIDs[i], ProductName = _productManager.RetrieveProductById(supplierApplicant.ProductIDs[i]).Name }); } } if (ModelState.IsValid) { //Need to first make a user with the information, then the supplier User newUser = new User() { FirstName = supplierApplicant.FirstName, LastName = supplierApplicant.LastName, City = supplierApplicant.City, State = supplierApplicant.State, AddressLineOne = supplierApplicant.AddressLineOne, AddressLineTwo = supplierApplicant.AddressLineTwo, Zip = supplierApplicant.Zip, EmailAddress = supplierApplicant.EmailAddress, EmailPreferences = true, Active = true, Phone = supplierApplicant.Phone, UserName = supplierApplicant.UserName }; try { string result = _userManager.CreateNewUser(newUser, supplierApplicant.Password, supplierApplicant.ConfirmPassword); if (!("Created".Equals(result))) { ViewBag.Message = result; return(View(supplierApplicant)); } } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } // If we are here, it means we created the user User newlyCreated = null; try { newlyCreated = _userManager.RetrieveUserByUserName(newUser.UserName); } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } if (null == newlyCreated) // this shouldn't ever be true { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } // Make a supplier and store the associated data to the db SupplierWithAgreements supplierWithAgreements = new SupplierWithAgreements() { FarmName = supplierApplicant.FarmName, FarmAddress = supplierApplicant.FarmAddress, FarmCity = supplierApplicant.FarmCity, FarmState = supplierApplicant.FarmState, FarmTaxID = supplierApplicant.FarmTaxID, UserId = newlyCreated.UserId, ProductIDs = supplierApplicant.ProductIDs, Agreements = supplierApplicant.Agreements, Active = true, IsApproved = false }; try { if (_supplierManager.ApplyForSupplierAccount(supplierWithAgreements)) { supplierWithAgreements.SupplierID = _supplierManager.RetrieveSupplierByUserId(supplierWithAgreements.UserId).SupplierID; foreach (Agreement a in supplierWithAgreements.Agreements) { if (!_agreementManager.CreateAgreementsForSupplier(supplierWithAgreements, _productManager.RetrieveProductById(a.ProductId))) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } } RegisterViewModel registerModel = new RegisterViewModel() { Email = newUser.EmailAddress, Password = supplierApplicant.Password, ConfirmPassword = supplierApplicant.ConfirmPassword }; var controller = DependencyResolver.Current.GetService <AccountController>(); controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller); var result = await controller.Register(registerModel); return(RedirectToAction("ApplicationSuccess", "Home", new { username = newlyCreated.UserName, supOrCom = true })); //return RedirectToAction("Register", "Account", registerModel); } else { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } } catch (Exception) { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } } List <Product> products = _productManager.ListProducts(); supplierApplicant.Agreements = new List <AgreementWithProductName>(); foreach (Product p in products) { supplierApplicant.Agreements.Add(new AgreementWithProductName() { ProductId = p.ProductId, ProductName = p.Name }); } return(View(supplierApplicant)); }