public ActionResult ResetOrderStatus(int id) { try { GATE_MaterialRequest oldRequest = DB.GATE_MaterialRequest .Include(x => x.MaterialAction) .Include(x => x.Message) .Include(x => x.Package) .Include(x => x.Package.GenericMaterials) .First(x => x.MaterialRequestId == id); oldRequest.OrderStatusId = OrderStatus.Cancelled; oldRequest.CancellationComment = "Order reset"; GATE_MaterialRequest newRequest = new GATE_MaterialRequest { OrderStatusId = OrderStatus.HelpDeskProductProposal, ConcernedEmployeeId = oldRequest.ConcernedEmployeeId, OrderedByEmployeeId = oldRequest.OrderedByEmployeeId, PackageId = oldRequest.PackageId, RequestDate = oldRequest.RequestDate, ExpectedDate = oldRequest.ExpectedDate, Comment = oldRequest.Comment, AddressId = oldRequest.AddressId, AmarisOfficeId = oldRequest.AmarisOfficeId, CurrencyId = oldRequest.CurrencyId, OrderTypeId = oldRequest.OrderTypeId, TotalCost = oldRequest.TotalCost, IsAutomated = oldRequest.IsAutomated, MaterialAction = oldRequest.MaterialAction.ToList(), Message = oldRequest.Message.ToList() }; //cloning the old list using ToList() //Request the individual components (aparently this is necessary, although I am not sure why ...) Package thePackage = oldRequest.Package; foreach (var material in thePackage.GenericMaterials) { GATE_ComponentRequest component = new GATE_ComponentRequest { MaterialId = material.GenericMaterialId, IsSetup = !material.RequiresSetup, IsDispatched = false, MaterialRequestId = newRequest.MaterialRequestId, StatusId = OrderStatus.HelpDeskProductProposal }; DB.GATE_ComponentRequest.Add(component); } //Adding new Material Actions and Messages foreach (MaterialAction action in newRequest.MaterialAction) { DB.MaterialActions.Add(action); } foreach (Message message in newRequest.Message) { DB.Messages.Add(message); } DB.GATE_MaterialRequest.Add(newRequest); DB.SaveChanges(); DB.GATE_MaterialRequest.UpdatePermissions(newRequest.MaterialRequestId); return new HttpStatusCodeResult(HttpStatusCode.OK); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message); } }
public ActionResult EditSuggestion(GATE_ComponentRequest suggestion, HttpPostedFileWrapper pictureUpload = null) { if (!suggestion.InStock) { if (suggestion.CurrentSuggestion.Price == null) { ModelState.AddModelError("MaterialSuggestion.Price", "Price is required"); } if (suggestion.CurrentSuggestion.Label == null) { ModelState.AddModelError("MaterialSuggestion.Label", "Label is required"); } } else { suggestion.CurrentSuggestion.Label = "In Stock"; suggestion.CurrentSuggestion.Price = 0; } if (pictureUpload != null && pictureUpload.ContentType.Substring(0, 5) != "image") { ModelState.AddModelError("pictureUpload", "The file you tried to insert is not an image file, you should use .jpg, .png or .gif"); } var componentRequest = DB.GATE_ComponentRequest.Include(x => x.CurrentSuggestion) .Include(x => x.PreviousSuggestion) .Where(x => x.ComponentId == suggestion.ComponentId) .Select(x => x).FirstOrDefault(); if (componentRequest.PreviousMaterialSuggestedId == null) { var matSuggestion = new GATE_MaterialSuggestion { Label = componentRequest.CurrentSuggestion.Label, Price = componentRequest.CurrentSuggestion.Price, DeliveryDate = componentRequest.CurrentSuggestion.DeliveryDate, CurrencyId = componentRequest.CurrentSuggestion.CurrencyId, IsNotStandardProduct = componentRequest.CurrentSuggestion.IsNotStandardProduct, PictureId = componentRequest.CurrentSuggestion.PictureId, InStock = componentRequest.CurrentSuggestion.InStock }; componentRequest.PreviousSuggestion = matSuggestion; DB.GATE_MaterialSuggestion.Add(componentRequest.PreviousSuggestion); DB.SaveChanges(); } else { componentRequest.PreviousSuggestion.Label = componentRequest.CurrentSuggestion.Label; componentRequest.PreviousSuggestion.Price = componentRequest.CurrentSuggestion.Price; componentRequest.PreviousSuggestion.DeliveryDate = componentRequest.CurrentSuggestion.DeliveryDate; componentRequest.PreviousSuggestion.CurrencyId = componentRequest.CurrentSuggestion.CurrencyId; componentRequest.PreviousSuggestion.IsNotStandardProduct = componentRequest.CurrentSuggestion.IsNotStandardProduct; componentRequest.PreviousSuggestion.PictureId = componentRequest.CurrentSuggestion.PictureId; componentRequest.PreviousSuggestion.InStock = componentRequest.CurrentSuggestion.InStock; DB.Entry(componentRequest.PreviousSuggestion).State = EntityState.Modified; DB.SaveChanges(); } componentRequest.CurrentSuggestion.Label = suggestion.CurrentSuggestion.Label; componentRequest.CurrentSuggestion.Price = suggestion.CurrentSuggestion.Price; componentRequest.CurrentSuggestion.DeliveryDate = suggestion.CurrentSuggestion.DeliveryDate; componentRequest.CurrentSuggestion.CurrencyId = suggestion.CurrentSuggestion.CurrencyId; componentRequest.CurrentSuggestion.IsNotStandardProduct = suggestion.CurrentSuggestion.IsNotStandardProduct; componentRequest.CurrentSuggestion.InStock = suggestion.InStock; if (pictureUpload != null && pictureUpload.ContentType.Substring(0, 5) == "image") { var b = new BinaryReader(pictureUpload.InputStream); byte[] binData = b.ReadBytes(pictureUpload.ContentLength); var pictureFile = new GATE_SuggestionPicture { PictureData = binData }; componentRequest.CurrentSuggestion.GATE_SuggestionPicture = pictureFile; } DB.Entry(componentRequest.CurrentSuggestion).State = EntityState.Modified; DB.SaveChanges(); return new RedirectResult(Url.Action("Pending") + "#tr" + componentRequest.MaterialRequestId); }
public ActionResult CreateSuggestion(GATE_ComponentRequest suggestion, HttpPostedFileWrapper pictureUpload) { //TODO reimplement with the new Stock and password tables #stock if (!suggestion.InStock) { if (suggestion.CurrentSuggestion.Price == null) { ModelState.AddModelError("MaterialSuggestion.Price", "Price is required"); } if (suggestion.CurrentSuggestion.Label == null) { ModelState.AddModelError("MaterialSuggestion.Label", "Label is required"); } } else { suggestion.CurrentSuggestion.Label = "In Stock"; suggestion.CurrentSuggestion.Price = 0; } if (pictureUpload != null && pictureUpload.ContentType.Substring(0, 5) != "image") { ModelState.AddModelError("pictureUpload", "The file you tried to insert is not an image file, you should use .jpg, .png or .gif"); } var componentRequest = DB.GATE_ComponentRequest.Find(suggestion.ComponentId); GATE_MaterialSuggestion matSuggestion = suggestion.CurrentSuggestion; componentRequest.CurrentSuggestion = matSuggestion; if (pictureUpload != null && pictureUpload.ContentType.Substring(0, 5) == "image") { var b = new BinaryReader(pictureUpload.InputStream); byte[] binData = b.ReadBytes(pictureUpload.ContentLength); var pictureFile = new GATE_SuggestionPicture { PictureData = binData, }; componentRequest.CurrentSuggestion.GATE_SuggestionPicture = pictureFile; } else { componentRequest.CurrentSuggestion.PictureId = null; } DB.GATE_MaterialSuggestion.Add(matSuggestion); DB.SaveChanges(); return new RedirectResult(Url.Action("Pending") + "#tr" + componentRequest.MaterialRequestId); }
public ActionResult XEditOrderPackage(int pk, string name, string value) { GATE_MaterialRequest request = DB.GATE_MaterialRequest.Find(pk); Package thePackage = DB.Packages.Find(Int32.Parse(value)); List<GATE_ComponentRequest> components = new List<GATE_ComponentRequest>(); foreach (var material in thePackage.GenericMaterials) { GATE_ComponentRequest component = new GATE_ComponentRequest { MaterialId = material.GenericMaterialId, IsSetup = material.RequiresSetup, MaterialRequestId = request.MaterialRequestId, StatusId = OrderStatus.HelpDeskProductProposal }; components.Add(component); DB.GATE_ComponentRequest.Add(component); } DB.GATE_ComponentRequest.RemoveRange(request.ComponentRequests); request.ComponentRequests = components; DB.SaveChanges(); foreach (GATE_ComponentRequest component in request.ComponentRequests) { GATE_MaterialSuggestion newSuggestion = new GATE_MaterialSuggestion { InStock = false, IsNotStandardProduct = false, Label = string.Empty }; DB.GATE_MaterialSuggestion.Add(newSuggestion); component.CurrentSuggestion = newSuggestion; } DB.SaveChanges(); return XEditableUpdate(DB.GATE_MaterialRequest, pk, name, value); }
public ActionResult UpdateOrderPackage(int reqId, string pkgName) { try { GATE_MaterialRequest matReq = DB.GATE_MaterialRequest.Find(reqId); Package pkg = DB.Packages.FirstOrDefault(aPkg => aPkg.PackageName.Equals(pkgName)); DB.GATE_ComponentRequest.RemoveRange(matReq.ComponentRequests); matReq.PackageId = pkg.PackageId; foreach (var material in pkg.GenericMaterials) { GATE_ComponentRequest component = new GATE_ComponentRequest { MaterialId = material.GenericMaterialId, IsSetup = !material.RequiresSetup, IsDispatched = false, MaterialRequestId = matReq.MaterialRequestId }; DB.GATE_ComponentRequest.Add(component); } DB.SaveChanges(); return new HttpStatusCodeResult(HttpStatusCode.OK); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message); } }
public void DnaNewOrder(int newEmployeeId) { //1. Function + Company found(Host By) //2. Function only found //3. Default package Employee newEmployee = DB.Employees.Find(newEmployeeId); if (newEmployee == null) { Response.Write("No employees with that Id were found"); return; } GATE_MaterialRequest newRequest = new GATE_MaterialRequest { AmarisOfficeId = (newEmployee.OfficeExtension != null ? newEmployee.OfficeExtension.OfficeId : -1), ConcernedEmployeeId = newEmployeeId, IsAutomated = true, RequestDate = DateTime.Today, OrderedByEmployeeId = newEmployee.ManagerId.GetValueOrDefault(), OrderStatusId = OrderStatus.HelpDeskProductProposal, OrderTypeId = 1 }; newRequest.Office = DB.Offices.Find(newRequest.AmarisOfficeId); //The ids of all the functions the new employee has (1 employee can have several functions) //Get functions by using scope var employeeFunctions = DB.Employee_Scope .Where(sco => sco.EmployeeId == newEmployeeId) .Select(sco => sco.FunctionId); //List of ids of all the functions each package has var packageFunctions = from package in DB.Packages select new { packageId = package.PackageId, packageFunctionIds = (from aFunction in package.Functions select aFunction.FunctionId) }; //Find if there is a package for the specific functions of the new Employee //Match employee functions with package functions List<int> packageIds = new List<int>(); List<int> functionIds; foreach (var tuple in packageFunctions) { functionIds = (List<int>)tuple.packageFunctionIds; //Find if functionIds contains all items inside employeeFunctions //http://stackoverflow.com/questions/1520642/does-net-have-a-way-to-check-if-list-a-contains-all-items-in-list-b if (!employeeFunctions.Except(functionIds).Any() && employeeFunctions.Any()) { packageIds.Add(tuple.packageId); } } //There is a package with all the functions of the new Employee. We enter case 1 or 2 if (!packageIds.IsNullOrEmpty()) { //case 1: Function + Company List<Package> possibleTargets = new List<Package>(); //There is a package more specific for the employee if (!possibleTargets.IsNullOrEmpty()) { //case 1 newRequest.PackageId = possibleTargets.First().PackageId; } else { //case 2 newRequest.PackageId = packageIds.First(); } //Request the individual components (aparently this is necessary, although I am not sure why ...) Package thePackage = DB.Packages.Find(newRequest.PackageId); foreach (var material in thePackage.GenericMaterials) { GATE_ComponentRequest component = new GATE_ComponentRequest { MaterialId = material.GenericMaterialId, IsSetup = !material.RequiresSetup, IsDispatched = false, MaterialRequestId = newRequest.MaterialRequestId, StatusId = OrderStatus.HelpDeskProductProposal }; GATE_MaterialSuggestion newSuggestion = new GATE_MaterialSuggestion { InStock = false, IsNotStandardProduct = false, Label = string.Empty, CurrencyId = "EUR" }; DB.GATE_MaterialSuggestion.Add(newSuggestion); DB.GATE_ComponentRequest.Add(component); component.CurrentSuggestion = newSuggestion; } } //No package has the functions our Employee has, so we skip directly to order the default package else { //case 3 newRequest.PackageId = null; } MaterialAction firstAction = new MaterialAction { ActionId = 26, EmployeeId = newEmployee.ManagerId ?? newEmployeeId, DetailDate = DateTime.Now, Comment = "Order automatically created via external service" }; newRequest.MaterialAction.Add(firstAction); DB.MaterialActions.Add(firstAction); //set default Address Address defaultAddress = new Address { Complement = string.Empty, CreatedDate = DateTime.Now }; DB.Addresses.Add(defaultAddress); newRequest.AddressId = defaultAddress.ID; DB.GATE_MaterialRequest.Add(newRequest); DB.SaveChanges(); DB.GATE_MaterialRequest.UpdatePermissions(newRequest.MaterialRequestId); MailMan.SendAlertMails(newRequest); Response.Write("Request Sucessfull"); }