public ActionResult Create([Bind(Include = "CustomerId,CustomerName")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "OrderId,CustomerId,OrderName,OrderDate,OrderDeliveryDeadlineDate,OrderDeliveryDate,QuantityOrdered,QuantityDeliverded,OrderValue,OrderStatus")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "CustomerName", order.CustomerId); return(View(order)); }
public ActionResult Create([Bind(Include = "FilePathId,FileName,FileType,ProductId")] FilePath filePath) { if (ModelState.IsValid) { db.FilePaths.Add(filePath); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", filePath.ProductId); return(View(filePath)); }
public ActionResult Create([Bind(Include = "ProductOrderId,ProductId,OrderId")] ProductOrder productOrder) { if (ModelState.IsValid) { db.ProductOrders.Add(productOrder); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrderId = new SelectList(db.Orders, "OrderId", "OrderName", productOrder.OrderId); ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", productOrder.ProductId); return(View(productOrder)); }
public ActionResult Create([Bind(Include = "ProductId,ProductName,ProductsDescryption,ProductHeight,ProductWidth,ProductPrice")] Product product, HttpPostedFileBase upload) { if (ModelState.IsValid) { UploadImage(product, upload); db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public bool Add(ElectricItem electricItem) { var companyLogic = new CompanyLogic(); var companyId = companyLogic.GetCompanyId(electricItem.CompanyName); var electric = _context.Electrics.FirstOrDefault(item => item.CompanyId == companyId && item.Year == electricItem.Year && item.Month == electricItem.Month); if (electric != null) { electric.Electricity = electricItem.Electricity; electric.BuyElectricity = electricItem.BuyElectricity; electric.BuyAvgPrice = electricItem.BuyAvgPrice; electric.SellElectricity = electricItem.SellElectricity; electric.SellAvgPrice = electricItem.SellAvgPrice; electric.ModifyTime = DateTime.Now; } else { var entity = new Electric { CompanyId = companyId, Year = electricItem.Year, Month = electricItem.Month, Electricity = electricItem.Electricity, BuyElectricity = electricItem.BuyElectricity, BuyAvgPrice = electricItem.BuyAvgPrice, SellElectricity = electricItem.SellElectricity, SellAvgPrice = electricItem.SellAvgPrice, CreateTime = DateTime.Now, ModifyTime = DateTime.Now }; _context.Electrics.Add(entity); } _context.SaveChanges(); return(true); }
/// <summary> /// 修改密码 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <returns></returns> public bool Modify(string account, string password) { var user = _context.Users.FirstOrDefault(item => item.Account.Equals(account)); if (user == null) { return(false); } user.Password = password; user.ModifyTime = DateTime.Now; _context.SaveChanges(); return(true); }
public int Add(IList <CompanyItem> companies) { foreach (var companyItem in companies) { if (string.IsNullOrEmpty(companyItem.Name.Trim(' '))) { continue; } if (_context.Companies.FirstOrDefault(item => item.Name == companyItem.Name) != null) { continue; } var company = new Company { Name = companyItem.Name, CreateTime = DateTime.Now, ModifyTime = DateTime.Now }; _context.Companies.Add(company); } _context.SaveChanges(); return(1); }
/*This method will modify the data inside a specified id, must fulfill the specified conditions obviously. * Data has to be inserted according to the model and be sure that there is no duplication of key values inside the database */ public IHttpActionResult PutProducts(int id, ProductsModel products) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != products.Id) { return(BadRequest()); } db.Entry(products).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductsExists(id)) { return(NotFound()); } else { throw; } } catch (System.Data.Entity.Infrastructure.DbUpdateException) { return(StatusCode(HttpStatusCode.Forbidden)); } return(StatusCode(HttpStatusCode.NoContent)); }
public bool Add(ProfitItem profitItem) { var companyLogic = new CompanyLogic(); var companyId = companyLogic.GetCompanyId(profitItem.CompanyName); var profit = _context.Profits.FirstOrDefault(item => item.CompanyId == companyId && item.Year == profitItem.Year && item.Month == profitItem.Month); if (profit != null) { profit.AssetsImpairmentLoss = profitItem.AssetsImpairmentLoss; profit.EngineeringAndLeasehold = profitItem.EngineeringAndLeasehold; profit.FinancialCost = profitItem.FinancialCost; profit.ProfitValue = profitItem.ProfitValue; profit.OtherCost = profitItem.OtherCost; profit.TaxAndAdditional = profitItem.TaxAndAdditional; profit.ThirdMaintenanceFee = profitItem.ThirdMaintenanceFee; profit.ModifyTime = DateTime.Now; } else { var entity = new Profit { CompanyId = companyId, Year = profitItem.Year, Month = profitItem.Month, AssetsImpairmentLoss = profitItem.AssetsImpairmentLoss, EngineeringAndLeasehold = profitItem.EngineeringAndLeasehold, FinancialCost = profitItem.FinancialCost, ProfitValue = profitItem.ProfitValue, OtherCost = profitItem.OtherCost, TaxAndAdditional = profitItem.TaxAndAdditional, ThirdMaintenanceFee = profitItem.ThirdMaintenanceFee, CreateTime = DateTime.Now, ModifyTime = DateTime.Now }; _context.Profits.Add(entity); } _context.SaveChanges(); return(true); }
public bool Add(CostItem costItem) { var companyLogic = new CompanyLogic(); var companyId = companyLogic.GetCompanyId(costItem.CompanyName); var cost = _context.Costs.FirstOrDefault(item => item.CompanyId == companyId && item.Year == costItem.Year && item.Month == costItem.Month); if (cost != null) { cost.Salary = costItem.Salary; cost.WorkersWelfare = costItem.WorkersWelfare; cost.TotalCost = costItem.TotalCost; cost.ControllableCost = costItem.ControllableCost; cost.OtherControllableCost = costItem.ControllableCost - costItem.WorkersWelfare; cost.OtherUnControllableCost = costItem.TotalCost - costItem.ControllableCost - costItem.Salary; cost.ModifyTime = DateTime.Now; } else { var entity = new Cost() { Year = costItem.Year, Month = costItem.Month, Salary = costItem.Salary, WorkersWelfare = costItem.WorkersWelfare, TotalCost = costItem.TotalCost, ControllableCost = costItem.ControllableCost, OtherControllableCost = costItem.ControllableCost - costItem.WorkersWelfare, OtherUnControllableCost = costItem.TotalCost - costItem.ControllableCost - costItem.Salary, CreateTime = DateTime.Now, ModifyTime = DateTime.Now }; entity.CompanyId = companyId; _context.Costs.Add(entity); } _context.SaveChanges(); return(true); }
private static void InsertCategoryToCategoryRelation(Category parentCategory, Category childCategory) { parentCategory.ChildrenCategories.Add(childCategory); Context.SaveChanges(); }