public IHttpActionResult PutEventLog(int id, EventLog eventLog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != eventLog.ID) { return(BadRequest()); } db.Entry(eventLog).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EventLogExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "ID,Name")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public async Task <ActionResult> Delete(string modalValue) { var contract = ctx.Contracts.FirstOrDefault(c => c.Id == modalValue); if (ctx.Queries.Count(q => q.Contract.Id == contract.Id) > 0) { TempData["Error"] = contract.Id; return(RedirectToAction("GoToList")); } ctx.Contracts.Remove(contract); ctx.SaveChanges(); await CallToMLAsync(new { ContractId = contract.Id, UserName = "******" }, "api/Contract/Delete"); return(RedirectToAction("GoToList")); }
public ActionResult Create([Bind(Include = "SubscriptionID,CustomerID,ServiceID,Price,Term")] Subscription subscription) { var customerID = subscription.CustomerID; if (ModelState.IsValid) { db.Subscriptions.Add(subscription); db.SaveChanges(); return(RedirectToAction("Details", "Customer", new { ID = customerID })); } ViewBag.CustomerID = customerID; ViewBag.ServiceID = new SelectList(db.Services, "ID", "Name", subscription.ServiceID); return(View(subscription)); }
public ActionResult CreateContract (string CustomerName, string ProductType, decimal Price, DateTime Date, string CustomerType, int BankNumber, string Adress) { Contract contract = new Contract { CustomerName = CustomerName, ProductType = ProductType, Price = Price, Date = Date, CustomerType = CustomerType, BankNumber = BankNumber, Adress = Adress, Status = "Sold" }; try { // Записываем котнтракт в БД\ db.Contracts.Add(contract); db.SaveChanges(); } catch (Exception ex) { return(View(ex.Message)); } return(RedirectToAction("Index", "Home")); }
//[ClassInitialize] public static void Init(TestContext context) { //Used for connectionstring AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Directory.GetCurrentDirectory()); var db = new ContractContext(""); db.Contracts.RemoveRange(db.Contracts); db.SaveChanges(); }
public async Task <ActionResult> Create(AdapterServer ads) { if (ads.ISName == null || ads.Root == null || ads.Url == null) { ViewBag.Error = "You must fill all inputs !"; return(View("Create")); } if (ctx.AdapterServers.Any(a => a.ISName == ads.ISName)) { ViewBag.Error = "This Adapter Server already exists !"; return(View("Create")); } else { ctx.AdapterServers.Add(ads); ctx.SaveChanges(); await CallToMLAsync(new { UserName = ads.ISName, UserType = "TEMP" }, "api/AdapterServer/Add"); ViewBag.Message = "Adapter Server successfully added !"; return(View("Create")); } }
static void Main(string[] args) { var contractFiles = Directory.GetFiles(@"C:\Users\SSV\Documents\Visual Studio 2017\Projects\XmlToSqlProject\ShortContract\contracts"); var contractProvider = new ContractXmlProvider(); List <ContractXmlModel> contractXmlList = new List <ContractXmlModel>(); foreach (var item in contractFiles) { var contract = contractProvider.GetContract(item); contractXmlList.Add(contract); } var contracts = CustomersConverter.ConvertContracts(contractXmlList); var suppliers = contractXmlList.Select(m => CustomersConverter.ConvertSupplier(m.Supplier)); var customers = contractXmlList.Select(m => CustomersConverter.ConvertCustomer(m.Customer)); var uniqSuppliers = suppliers.Distinct(new SupplierComparer()).ToList(); var uniqCustomers = customers.Distinct(new CustomerComparer()).ToList(); foreach (var item in contracts) { var sup = uniqSuppliers.FirstOrDefault(s => s.Inn.Equals(item.Supplier.Inn)); item.Supplier = sup; var cus = uniqCustomers.FirstOrDefault(s => s.Inn.Equals(item.Customer.Inn)); item.Customer = cus; } //foreach (var sup in uniqSuppliers) //{ // var contr = contracts.Where(c => c.SupplierId.Equals(sup.Id)); // foreach (var item in contr) // { // sup.Contracts.Add(item); // } //} //foreach (var cust in uniqCustomers) //{ // var contr = contracts.Where(c => c.CustomerId.Equals(cust.Inn)); // foreach (var item in contr) // { // cust.Contracts.Add(item); // } //} using (ContractContext context = new ContractContext()) { //context.Contracts.RemoveRange(context.Contracts); // context.Suppliers.RemoveRange(context.Suppliers); // context.SaveChanges(); //context.Suppliers.AddRange(uniqSuppliers); context.Contracts.AddRange(contracts); // context.SaveChanges(); } Console.ReadLine(); }
public void Add(LoginModel entity) { _contractContext.LoginModels.Add(entity); _contractContext.SaveChanges(); }
public void Add(Contract entity) { _contractContext.Contracts.Add(entity); _contractContext.SaveChanges(); }