public IActionResult Delete(int id) { Product product = _unityOfWork.Product.GetByIdForDelete(id); Angle.Models.ViewModels.ProductViewModel.ProductViewModel productToDelete = new Angle.Models.ViewModels.ProductViewModel.ProductViewModel() { ID = product.ID, Description = product.Description, SerialNumber = product.SerialNumber, }; var childs = _unityOfWork.Product.getChilds(product.ID); List <string> myChilds = new List <string>(); foreach (var child in childs) { myChilds.Add(child.Description); } productToDelete.TypeChild = myChilds.ToArray(); if (product.Parent != null) { productToDelete.ParentID = product.ParentID; productToDelete.ParentName = product.Parent.Description; } LoggingController.writeLog(productToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(View(productToDelete)); }
public IActionResult Edit(ProjectModel project) { _unityOfWork.Project.Update(project); _unityOfWork.Save(); LoggingController.writeLog(project, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public async Task <JsonResult> QuickAddHistory(CreateProductHistoryViewModel model) { if (model.UploadFile != null) { var uploads = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads"); if (model.UploadFile.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, model.UploadFile.FileName), FileMode.Create)) { await model.UploadFile.CopyToAsync(fileStream); } Upload myFile = new Upload() { RelativPath = Path.Combine(uploads, model.UploadFile.FileName), Size = model.UploadFile.Length.ToString(), Format = model.UploadFile.ContentType.ToString(), }; _unityOfWork.Upload.Insert(myFile); _unityOfWork.Save(); model.UploadID = myFile.ID; } } try { Product product = _unityOfWork.Product.GetById(model.ProductID); ProductHistory productHistory = new ProductHistory { UserID = _db.Users.FirstOrDefault(x => x.Email == model.Email).Id, Comment = model.Comment, Date = DateTime.Now, ProductID = model.ProductID, HistoryID = model.HistoryID, FileID = model.UploadID }; product.ProductHistories.Add(productHistory); _unityOfWork.Product.Update(product); _unityOfWork.Save(); productHistory.User = null; productHistory.UserID = null; LoggingController.writeLog(productHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(Json(productHistory)); } catch { return(Json(null)); } }
public IActionResult Delete(Angle.Models.ViewModels.ProductViewModel.ProductViewModel productToDelete) { Product product = _unityOfWork.Product.GetById(productToDelete.ID); List <Product> Childs = _unityOfWork.Product.getChilds(product.ID); _unityOfWork.Product.Delete(product); _unityOfWork.Save(); LoggingController.writeLog(product, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddHistory(CreateProductHistoryViewModel model) { if (model.UploadFile != null) { var uploads = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads"); if (model.UploadFile.Length > 0) { string fName = Path.GetFileNameWithoutExtension(model.UploadFile.FileName); string fExt = Path.GetExtension(model.UploadFile.FileName); string hashCode = RandomString(5); string newUniqueFileName = String.Concat(fName, "_" + hashCode, fExt); using (var fileStream = new FileStream(Path.Combine(uploads, newUniqueFileName), FileMode.Create)) { await model.UploadFile.CopyToAsync(fileStream); } Upload myFile = new Upload() { RelativPath = Path.Combine(uploads, newUniqueFileName), Size = model.UploadFile.Length.ToString(), Format = model.UploadFile.ContentType.ToString(), }; _unityOfWork.Upload.Insert(myFile); _unityOfWork.Save(); model.UploadID = myFile.ID; } } Product product = _unityOfWork.Product.GetById(model.ProductID); ProductHistory productHistory = new ProductHistory { UserID = _db.Users.FirstOrDefault(x => x.Email == model.Email).Id, Comment = model.Comment, Date = DateTime.Now, ProductID = model.ProductID, HistoryID = model.HistoryID, FileID = model.UploadID }; product.ProductHistories.Add(productHistory); _unityOfWork.Product.Update(product); _unityOfWork.Save(); productHistory.User = null; productHistory.UserID = null; LoggingController.writeLog(productHistory, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(Redirect(Request.Headers["Referer"])); }
public ActionResult Create(History history) { try { _unityOfWork.History.Insert(history); _unityOfWork.Save(); return(RedirectToAction("Index", "History")); LoggingController.writeLog(history, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); } catch { return(View()); } }
public ActionResult Delete(int id) { try { var historyType = _unityOfWork.History.GetById(id); _unityOfWork.History.Delete(historyType); _unityOfWork.Save(); LoggingController.writeLog(historyType, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction(nameof(Index))); } catch { return(View(nameof(Index))); } }
public JsonResult CreateOnPost(History history) { try { _unityOfWork.History.Insert(history); _unityOfWork.Save(); var historytypes = _unityOfWork.History.GetAll(); return(Json(historytypes)); LoggingController.writeLog(history, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); } catch { var historytypes = _unityOfWork.History.GetAll(); return(Json(historytypes)); } }
public ActionResult Edit(History model) { try { var historyType = _unityOfWork.History.GetById(model.ID); historyType.Description = model.Description; historyType.BootStrapBadge = model.BootStrapBadge; _unityOfWork.History.Update(historyType); _unityOfWork.Save(); LoggingController.writeLog(historyType, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public IActionResult Delete(DeleteProjectViewModel project) { ProjectModel projectToDelete = new ProjectModel() { ID = project.ID, CustomerID = project.CustomerID, Description = project.Description, Title = project.Title }; if (project.decisionControll) { _unityOfWork.Project.Delete(projectToDelete); _unityOfWork.Save(); } LoggingController.writeLog(projectToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public IActionResult Delete(TypeDeleteViewModel typeToDelete) { var myTypeToDelete = _unityOfWork.Type.GetById(typeToDelete.ID); typeToDelete.Products = _unityOfWork.Product.getProductsByType(Convert.ToInt32(typeToDelete.ID)); var deleteAllProducts = typeToDelete.deleteProducts; if (deleteAllProducts) { foreach (var product in typeToDelete.Products) { _unityOfWork.Product.Delete(product); } } _unityOfWork.Type.Delete(myTypeToDelete); _unityOfWork.Save(); LoggingController.writeLog(myTypeToDelete, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public IActionResult Edit(ProductCreateViewModel product) { LoggingController.writeLog(product, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); List <Attribute> attributes = new List <Attribute>(); int arrIndex = 0; Product myProduct = new Product() { ID = product.ID, CustomerID = product.CustomerID, Description = product.Description, ProjectID = product.ProjectID, SerialNumber = product.SerialNumber, DeviceTypeID = product.DeviceTypeID, StockInformationID = product.StockInformationID, ParentID = product.ParentID, }; myProduct.ProductAttributes.Clear(); if (product.SelectedAttributes != null) { foreach (var attribute in product.SelectedAttributes) { ProductAttribute model = new ProductAttribute { AttributeID = Convert.ToInt32(attribute), Value = product.ValueSelectedAttributes[arrIndex], ProductID = product.ID }; arrIndex++; myProduct.ProductAttributes.Add(model); } } _unityOfWork.Product.Update(myProduct); _unityOfWork.Save(); //var childToExclude = _unityOfWork.Product.getChilds(myProduct.ID); var productChilds = _unityOfWork.Product.getChilds(myProduct.ID); foreach (var child in productChilds) { child.ParentID = null; _unityOfWork.Product.Update(child); } _unityOfWork.Save(); try { foreach (string productChild in product.TypeChild) { var childProduct = _unityOfWork.Product.GetById(Convert.ToInt32(productChild)); childProduct.ParentID = myProduct.ID; _unityOfWork.Product.Update(childProduct); } _unityOfWork.Save(); } catch { } LoggingController.writeLog(product, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public IActionResult Create(ProductCreateViewModel product) { List <Attribute> attributes = new List <Attribute>(); int arrIndex = 0; ProductHistory history = new ProductHistory() { UserID = _db.Users.FirstOrDefault(x => x.Email == product.Email).Id, HistoryID = _unityOfWork.History.GetByName("Created"), Date = DateTime.Now, Comment = "Created" }; Product myProduct = new Product() { CustomerID = product.CustomerID, Description = product.Description, ProjectID = product.ProjectID, SerialNumber = product.SerialNumber, DeviceTypeID = product.DeviceTypeID, StockInformationID = product.StockInformationID, }; if (product.SelectedAttributes != null) { foreach (string item in product.SelectedAttributes) { Attribute attr = _unityOfWork.Attribute.GetById(Convert.ToInt32(item)); myProduct.ProductAttributes.Add(new ProductAttribute() { AttributeID = attr.ID, Value = product.ValueSelectedAttributes[arrIndex] } );; arrIndex++; } } myProduct.ProductHistories.Add(history); _unityOfWork.Product.Insert(myProduct); _unityOfWork.Save(); int counterOptionsValues = 0; foreach (var optionID in product.SelectedSoftwareOptions) { ProductSoftwareOptions productSoftwareOption = new ProductSoftwareOptions() { ProductID = myProduct.ID, SoftwareOptionID = Convert.ToInt32(optionID), SoftwareTypeID = product.SoftwareID ?? 0, Product = myProduct, SoftwareOption = _db.SoftwareOptions.FirstOrDefault(x => x.ID == Convert.ToInt32(optionID)), SoftwareType = _db.SoftwareTypes.FirstOrDefault(c => c.ID == product.SoftwareID), Value = product.ValueSelectedOptions[counterOptionsValues] }; counterOptionsValues++; _db.ProductSoftwareOptions.Add(productSoftwareOption); _db.SaveChanges(); } try { foreach (string productChild in product.TypeChild) { var childProduct = _unityOfWork.Product.GetById(Convert.ToInt32(productChild)); childProduct.ParentID = myProduct.ID; _unityOfWork.Product.Update(childProduct); _unityOfWork.Save(); } } catch { } LoggingController.writeLog(product, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public IActionResult Create(TypeCreateViewModel type) { int arrIndex = 0; PType myType = new PType() { Name = type.Name, Description = type.Description, }; if (type.SelectedFeatures != null) { foreach (long feature in type.SelectedFeatures) { myType.TypeFeatures.Add(new TypeFeature() { FeatureID = feature }); } } if (type.SelectedAttributes != null) { foreach (string item in type.SelectedAttributes) { Attribute attr = _unityOfWork.Attribute.GetByName(item); myType.TypeAttributes.Add(new TypeAttribute() { AttributeID = attr.ID, Value = type.ValueSelectedAttributes[arrIndex] } );; arrIndex++; } } List <long> existingChilds = new List <long>(); if (type.TypeChild != null) { foreach (long child in type.TypeChild) { if (!existingChilds.Contains(child)) { myType.Childs.Add(new TypeChild() { ChildID = child, Quantity = type.TypeChild.Where(p => p == child).Count() });; existingChilds.Add(child); } } } _unityOfWork.Type.Insert(myType); _unityOfWork.Save(); LoggingController.writeLog(myType, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }
public IActionResult Edit(TypeCreateViewModel type) { int arrIndex = 0; PType myType = _unityOfWork.Type.GetById(type.ID); myType.ID = type.ID; myType.Name = type.Name; myType.Description = type.Description; if (type.SelectedFeatures != null) { myType.TypeFeatures.Clear(); foreach (long feature in type.SelectedFeatures) { myType.TypeFeatures.Add(new TypeFeature() { FeatureID = feature }); } } if (type.SelectedAttributes != null) { myType.TypeAttributes = new List <TypeAttribute>(); foreach (string item in type.SelectedAttributes) { myType.TypeAttributes.Add(new TypeAttribute() { DeviceTypeID = type.ID, AttributeID = _unityOfWork.Attribute.GetByName(item).ID, Value = type.ValueSelectedAttributes[arrIndex] } );; arrIndex++; } } List <long> existingChilds = new List <long>(); if (type.TypeChild != null) { myType.Childs.Clear(); foreach (var childID in type.TypeChild) { int quantity = type.TypeChild.Where(b => b == childID).Count(); TypeChild model = new TypeChild() { TypeID = myType.ID, ChildID = childID, Quantity = quantity }; type.TypeChild = type.TypeChild.Where(b => b != childID).ToArray(); myType.Childs.Add(model); } } _unityOfWork.Type.Update(myType); _unityOfWork.Save(); // This part Update also Product Attribute of Existing Products var products = _unityOfWork.Product.getProductsByType(myType.ID); foreach (var product in products) { List <long> existingAttributes = new List <long>(); foreach (var p in product.ProductAttributes) { existingAttributes.Add(p.AttributeID); } foreach (var name in type.SelectedAttributes) { if (!existingAttributes.Contains(_unityOfWork.Attribute.GetByName(name).ID)) { ProductAttribute pa = new ProductAttribute { ProductID = product.ID, AttributeID = _unityOfWork.Attribute.GetByName(name).ID, }; product.ProductAttributes.Add(pa); } } _unityOfWork.Product.Update(product); existingAttributes.Clear(); } _unityOfWork.Save(); LoggingController.writeLog(myType, User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), this.ControllerContext.RouteData.Values["controller"].ToString()); return(RedirectToAction("Index")); }