public string UpdateSubAssembly(SubAssembly model) { using (IDbConnection connection = OpenConnection(dataConnection)) { IDbTransaction txn = connection.BeginTransaction(); try { Delete(model.StockCreationId, connection, txn); Create(model, connection, txn); InsertLoginHistory(dataConnection, model.CreatedBy, "Update", "Sub-assembly", model.StockCreationId.ToString(), model.OrganizationId.ToString()); txn.Commit(); return(model.StockCreationRefNo); } catch (SqlException sx) { txn.Rollback(); throw sx; } catch (Exception ex) { txn.Rollback(); throw ex; } } }
public ActionResult Create(SubAssembly model) { try { if (ModelState.IsValid) { model.OrganizationId = OrganizationId; model.CreatedDate = System.DateTime.Now; model.CreatedBy = UserID.ToString(); string ref_no = new SubAssemblyRepository().CreateSubAssembly(model); TempData["success"] = "Saved Successfully. Reference No. is " + ref_no; } else { var allErrors = ModelState.Values.SelectMany(v => v.Errors); FillDropdowns(); return(View(model)); } } catch (Exception ex) { TempData["error"] = "Some error occured while saving. Please try again.|" + ex.Message; FillDropdowns(); return(View(model)); } return(RedirectToAction("Create")); }
public MemoData(double V, SubAssembly S) { Value = V; sa = S; //Parents = new List<MemoData>(); //Children = new List<MemoData>(); }
public ActionResult Edit(SubAssembly model) { try { model.OrganizationId = OrganizationId; model.CreatedDate = System.DateTime.Now; model.CreatedBy = UserID.ToString(); string ref_no = new SubAssemblyRepository().UpdateSubAssembly(model); TempData["success"] = "Updated Successfully - " + ref_no; return(RedirectToAction("Index")); } catch (SqlException sx) { if (sx.Errors[0].Number == 547) { TempData["error"] = "Cannot update, because the record is in use elsewhere"; } else { TempData["error"] = "Some error occured while connecting to database|" + sx.Message; } } catch (Exception ex) { TempData["error"] = "Some error occured while saving. Please try again.|" + ex.Message; } FillDropdowns(); return(View("Create", model)); }
public SubAssembly GetSubAssembly(int id, int organizationId) { using (IDbConnection connection = OpenConnection(dataConnection)) { try { #region Get data from [StockCreation] head string query = @"SELECT StockCreationId, StockCreationRefNo, StockCreationDate, isSubAssembly, EmployeeId, WorkingHours, ConsumedStockpointId, FinishedStockpointId FROM StockCreation WHERE StockCreationId = @id AND OrganizationId = @organizationId AND isSubAssembly = 1 AND isActive = 1"; SubAssembly model = connection.Query <SubAssembly>(query, new { id = id, OrganizationId = organizationId }).First(); #endregion #region Get data from [StockCreationConsumedItems] query = @"SELECT ConsumedItemsId, StockCreationId, ItemId, Quantity, Rate FROM StockCreationConsumedItems WHERE StockCreationId = @id AND isActive = 1"; model.ConsumedItems = connection.Query <StockCreationConsumedItem>(query, new { id = id }).ToList(); #endregion #region Get data from [StockCreationFinishedGoods] query = @"SELECT FinishedGoodsId, StockCreationId, ItemId, Quantity, Rate FROM StockCreationFinishedGoods WHERE StockCreationId = @id AND isActive = 1"; model.FinishedGoods = connection.Query <StockCreationFinishedGood>(query, new { id = id }).ToList(); #endregion return(model); } catch (Exception) { return(new SubAssembly()); } } }
public JsonResult AddSubAssembly(SubAssembly SubAssembly) { var result = new { Success = "true", Message = "Success" }; try { int siteId = this._SubAssemblyService.Add(SubAssembly); } catch (Exception ex) { result = new { Success = "false", Message = "Problem in adding SubAssembly.Please contact Admin." }; } //return View("List"); return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Default constructor /// </summary> /// <param name="assemblyItem"></param> public FactorioAssembly(FactorioItem assemblyItem) { AssemblyItem = assemblyItem; Quantity = 1; if (assemblyItem.Recipe == null) { return; } foreach (var item in assemblyItem.Recipe) { SubAssembly.Add(new FactorioAssembly(item.Key, this, item.Value)); } }
public void GetSubAssemblyDetails_Should_Succeed() { var subAssembly = new SubAssembly() { Id = "1", AssemblyId = "1", Name = "subasdas", Quantity = 2, Weight = 3.50 }; this.Context.SubAssemblies.Add(subAssembly); this.Context.SaveChanges(); var result = this.subAssemblyService.GetSubAssemblyDetails(subAssembly.Id); result.Should().NotBeNull() .And.BeOfType <SubAssemblyDetailsOutputModel>(); }
public void CreatePart_Should_Succeed() { var subAssembly = new SubAssembly() { Id = "1", Name = "aasdasd", Quantity = 1, Weight = 1 }; var vendor = new Vendor() { Id = "1", Name = "vendor" }; this.Context.SubAssemblies.Add(subAssembly); this.Context.Vendors.Add(vendor); this.Context.SaveChanges(); var partInputModel = new PartInputModel { Name = "part1", Price = 2.50m, Quantity = 2, SubAssemblyId = subAssembly.Id, VendorName = vendor.Name }; var result = this.partService.Create(partInputModel).GetAwaiter().GetResult(); var part = this.Context.Parts.First(); result.Should().NotBeNull(); part.Should().NotBeNull() .And.Subject.Should().BeEquivalentTo(new { Id = result, ImageUrl = GlobalConstants.NoImageAvailableUrl, Name = partInputModel.Name }, options => options.ExcludingMissingMembers()); }
public void GetById_Should_Succeed() { var subAssembly = new SubAssembly() { Id = "1", AssemblyId = "1", Name = "subasdas", Quantity = 2, Weight = 3.50 }; this.Context.SubAssemblies.Add(subAssembly); this.Context.SaveChanges(); var result = this.subAssemblyService.GetById(subAssembly.Id); result.Should().NotBeNull() .And.Subject.As <SubAssembly>() .Name.Should().Be(subAssembly.Name); }
/// <summary> /// Constructor for subassemblies /// </summary> /// <param name="assemblyItem"></param> /// <param name="topAssembly"></param> /// <param name="quantity"></param> public FactorioAssembly(FactorioItem assemblyItem, FactorioAssembly topAssembly, int quantity) { AssemblyItem = assemblyItem; ItemQuantity = quantity; m_topAssembly = topAssembly; Quantity = (quantity * ((topAssembly.Quantity * topAssembly.AssemblyItem.Productivity)) / (assemblyItem.Productivity * topAssembly.AssemblyItem.CraftingOutput)); Quantity *= topAssembly.CraftingSpeed / CraftingSpeed; if (assemblyItem.Recipe != null) { foreach (var item in assemblyItem.Recipe) { SubAssembly.Add(new FactorioAssembly(item.Key, this, item.Value)); } } }
public string CreateSubAssembly(SubAssembly model) { using (IDbConnection connection = OpenConnection(dataConnection)) { IDbTransaction txn = connection.BeginTransaction(); try { model.StockCreationRefNo = DatabaseCommonRepository.GetNewDocNo(connection, model.OrganizationId, 26, true, txn); int id = Create(model, connection, txn); InsertLoginHistory(dataConnection, model.CreatedBy, "Create", "Sub-assembly", id.ToString(), model.OrganizationId.ToString()); txn.Commit(); return(model.StockCreationRefNo); } catch (Exception) { txn.Rollback(); throw; } } }
public void AddOrUpdate(List <ProductDto> productDTOList) { var productList = ctx.Product.Include(s => s.SubAssembly).Where(o => o.JobID == productDTOList[1].JobID).ToList(); //remove deleted products - productList .Where(d => !productDTOList.Any(dto => dto.ProductID == d.ProductID)).ToList() .ForEach(deleted => ctx.Product.Remove(deleted)); productDTOList.ToList().ForEach(ad => { var product = ctx.Product.Include(s => s.SubAssembly).FirstOrDefault(r => r.ProductID == ad.ProductID); if (product == null) { product = new Product(); ctx.Product.Add(product); } product.JobID = ad.JobID; product.ArchDescription = ad.ArchDescription; product.UnitID = ad.UnitID; product.UnitName = ad.UnitName; product.RoomName = ad.RoomName; product.ProductionDate = ad.ProductionDate; product.W = ad.W.GetValueOrDefault(); product.H = ad.H.GetValueOrDefault(); product.D = ad.D.GetValueOrDefault(); product.Delivered = ad.Delivered.GetValueOrDefault(); product.DeliveredDate = ad.DeliveryDate; product.Make = ad.Make; product.NIC = ad.NIC; //remove deleted subassemblies - product.SubAssembly .Where(d => !ad.SubAssemblies.Any(SubAssemblyDTO => SubAssemblyDTO.SubAssemblyID == d.SubAssemblyID)).ToList() .ForEach(deleted => ctx.SubAssembly.Remove(deleted)); //update or add SubAssembly -- ad.SubAssemblies.ToList().ForEach(od => { var subassembly = product.SubAssembly.FirstOrDefault(r => r.SubAssemblyID == od.SubAssemblyID); if (subassembly == null) { subassembly = new SubAssembly(); product.SubAssembly.Add(subassembly); } subassembly.ProductID = od.ProductID; subassembly.SubAssemblyName = od.SubAssemblyName; subassembly.MakeFile = od.MakeFile; subassembly.W = od.W; subassembly.H = od.H; subassembly.D = od.D; subassembly.GlassPartID = od.GlassPartID; subassembly.CPD_id = od.CPD_ID; }); }); ctx.SaveChanges(); }
public void DeleteRobot_Should_Succeed_With_All_Of_The_Nested_Classes() { var admin = new User() { Id = "123", Name = "Papuncho Kunchev", UserName = "******" }; var user = new User() { Id = "321", Name = "Kuncho Papunchev", UserName = "******" }; var robot = new Robot() { Id = "1", UserId = user.Id, Axes = 2, Name = "myRobot", SerialNumber = "2323" }; var assembly = new Assembly() { Id = "1", RobotId = robot.Id }; var subAssembly = new SubAssembly() { AssemblyId = assembly.Id, Id = "1", Quantity = 1, Weight = 1, Name = "Motherboard" }; var vendor = new Vendor() { Id = "1", Name = "IBM" }; var part = new Part() { Id = "1", Price = 2.50m, Quantity = 2, SubAssemblyId = subAssembly.Id, VendorId = vendor.Id }; userManager.CreateAsync(admin).GetAwaiter(); userManager.CreateAsync(user).GetAwaiter(); var role = new IdentityRole { Name = "admin" }; roleManager.CreateAsync(role).GetAwaiter(); userManager.AddToRoleAsync(admin, role.Name).GetAwaiter(); this.Context.Robots.Add(robot); this.Context.Assemblies.Add(assembly); this.Context.SubAssemblies.Add(subAssembly); this.Context.Parts.Add(part); this.Context.Vendors.Add(vendor); this.Context.SaveChanges(); robotService.DeleteRobot(robot.Id, admin.UserName); var result = this.Context.Robots.FirstOrDefault(); result.Should().BeNull(); }
public SubAssemblyView(SubAssembly subA) { this.subA = subA; subAssemController(); }
public static void GetTimeAndSD(SubAssembly sub, double[] testpoints, string actionname, out double time, out double SD) { time = 0; SD = 0; var inputdictionary = new Dictionary <List <double[]>, List <double[, ]> >(); double[,] subinputs; double[] userx; double usery, subtime, subsd; var userfeedbacks = new List <double[]>(); if (actionname.StartsWith("S") || actionname.StartsWith("s")) { userfeedbacks = usersecuredata; inputdictionary = SecureDictionary; Gethistoricaldata(testpoints, userfeedbacks, out usery); // usery = -1; // disable userfeedback if (usery != -1) { time = usery; SD = 0; } else { foreach (var otherf in sub.Secure.Fasteners) { if (otherf.SecureModelInputs != null) { if (EvaluationForBinaryTree.IsSameImputs(testpoints, otherf.SecureModelInputs) && otherf.Time > 0.001) //if time is included in subassembly { time = otherf.Time; SD = 0; break; } else { TimeAndSD(testpoints, inputdictionary, userfeedbacks, out time, out SD); break; } } } } } else { if (actionname.StartsWith("m") || actionname.StartsWith("M")) { userfeedbacks = usermovedata; inputdictionary = MoveDictionary; subinputs = sub.MoveRoateModelInputs; subtime = sub.MoveRoate.Time; subsd = sub.MoveRoate.TimeSD; } else if (actionname.StartsWith("i") || actionname.StartsWith("I")) { userfeedbacks = userinstalldata; inputdictionary = InstallDictionary; subinputs = sub.InstallModelInputs; subtime = sub.Install.Time; subsd = sub.Install.TimeSD; } else { userfeedbacks = userrotatedata; inputdictionary = RotateDictionary; subinputs = sub.RotateModelInputs; subtime = sub.Rotate.Time; subsd = sub.Rotate.TimeSD; } Gethistoricaldata(testpoints, userfeedbacks, out usery); // usery = -1; // disable userfeedback if (usery != -1) { time = usery; SD = 0; if (actionname.StartsWith("i") && time > 2.9 && time < 3.01) { var sss = 1; } } else { if (EvaluationForBinaryTree.IsSameImputs(testpoints, subinputs) && subtime != 0) //if time is included in subassembly { time = subtime; SD = subsd; if (actionname.StartsWith("i") && time > 2.9 && time < 3.01) { var sss = 1; } } else { TimeAndSD(testpoints, inputdictionary, userfeedbacks, out time, out SD); if (actionname.StartsWith("i") && time > 2.9 && time < 3.01) { var sss = 1; } } } } }
private int Create(SubAssembly model, IDbConnection connection, IDbTransaction txn) { try { #region Inserting into [StockCreation] head string query = @"INSERT INTO StockCreation ( StockCreationRefNo, StockCreationDate, isSubAssembly, EmployeeId, WorkingHours, CreatedBy, CreatedDate, OrganizationId, ConsumedStockpointId, FinishedStockpointId ) VALUES ( @StockCreationRefNo, @StockCreationDate, 1, @EmployeeId, @WorkingHours, @CreatedBy, @CreatedDate, @OrganizationId, @ConsumedStockpointId, @FinishedStockpointId ); SELECT CAST(SCOPE_IDENTITY() AS INT)"; int id = connection.Query <int>(query, model, txn).First(); #endregion #region Inserting Finished Goods + Stock Updation foreach (var item in model.FinishedGoods) { item.StockCreationId = id; var i = new StockCreationFinishedGoodsRepository().InsertFinishedGoods(item, connection, txn); new StockUpdateRepository().InsertStockUpdate(new StockUpdate { OrganizationId = model.OrganizationId, CreatedBy = model.CreatedBy, CreatedDate = model.CreatedDate, StockPointId = model.FinishedStockpointId, StockType = typeof(SubAssembly).Name, StockInOut = "IN", stocktrnDate = System.DateTime.Today, ItemId = item.ItemId, Quantity = item.Quantity, StocktrnId = id, StockUserId = model.StockCreationRefNo }, connection, txn); } #endregion #region Inserting Consumed Items + Stock Updation foreach (var item in model.ConsumedItems) { item.StockCreationId = id; var i = new StockCreationConsumedItemsRepository().InsertConsumedItems(item, connection, txn); new StockUpdateRepository().InsertStockUpdate(new StockUpdate { OrganizationId = model.OrganizationId, CreatedBy = model.CreatedBy, CreatedDate = model.CreatedDate, StockPointId = model.ConsumedStockpointId, StockType = typeof(SubAssembly).Name, StockInOut = "OUT", stocktrnDate = System.DateTime.Today, ItemId = item.ItemId, Quantity = item.Quantity * (-1), StocktrnId = id, StockUserId = model.StockCreationRefNo }, connection, txn); } #endregion return(id); } catch (Exception) { throw; } }