public ActionResult Create([Bind(Include = "Id,Price,Quantity,MedicineId,DeliveryId")] DeliveredMedicine deliveredMedicine) { var error = string.Empty; if (ModelState.IsValid) { try { deliveredMedicine.Id = Guid.NewGuid(); db.DeliveredMedicines.Add(deliveredMedicine); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbUpdateException ex) { error = ex.GetDeepestMessage(); } } ViewBag.DeliveryId = new SelectList(db.Deliveries, "Id", "Number", deliveredMedicine.DeliveryId); ViewBag.MedicineId = new SelectList(db.Medicines, "Id", "Name", deliveredMedicine.MedicineId); ViewBag.Error = error; return(View(deliveredMedicine)); }
public ActionResult Create([Bind(Include = "Id,Name,Code,AvailableQuantity")] Medicine medicine) { if (ModelState.IsValid) { medicine.Id = Guid.NewGuid(); db.Medicines.Add(medicine); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(medicine)); }
public Prescription Create(Prescription model) { var dal = model.ToDAL(); _db.Prescription.Add(dal); _db.SaveChanges(); _db.SaveChanges(); return(dal.ToBLL()); }
public IActionResult ModifyDoctor(ModifyDoctorRequest modifyDoctorRequest) { var list = _context.Doctor.Where(e => e.IdDoctor == modifyDoctorRequest.IdDoctor).ToList(); if (list.Count() == 0) { return(BadRequest(300)); } list.First().FirstName = modifyDoctorRequest.FirstName; list.First().LastName = modifyDoctorRequest.LastName; list.First().Email = modifyDoctorRequest.Email; _context.SaveChanges(); return(Ok("Doktor zmodyfikowany")); }
private void btnSave_Click(object sender, EventArgs e) { //try //{ PharmacyDbContext db = new PharmacyDbContext(); foreach (ListViewItem item in lvMedicine.Items) { Medicine medicine = new Medicine(); medicine.Name = item.SubItems[2].Text; medicine.Id = UniqueNumber.GenerateUniqueNumber(); medicine.CreatedBy = currentUser; medicine.CreatedDate = DateTime.Now; medicine.GroupId = GroupFactory.GetGroupId(item.SubItems[3].Text, currentUser); medicine.CompanyId = CompanyFactory.GetCompanyId(item.SubItems[4].Text, currentUser); db.Medicine.Add(medicine); } db.SaveChanges(); db.Dispose(); MessageBox.Show(@"Save successful!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); lvMedicine.Items.Clear(); //} //catch (Exception exception) //{ // MessageBox.Show("Saving Error:" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //} }
private void btnSave_Click(object sender, EventArgs e) { string expenseType = txtExpenseType.Text; if (expenseType == "") { MessageBox.Show("Expense can't be empty!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } PharmacyDbContext db = new PharmacyDbContext(); ExpenseType expenseTypes = new ExpenseType() { CreatedBy = currentUser, CreatedDate = DateTime.Now, Id = Guid.NewGuid().ToString(), Type = expenseType }; db.ExpenseType.Add(expenseTypes); db.SaveChanges(); db.Dispose(); MessageBox.Show("Save successful!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); txtExpenseType.Text = ""; }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { var user = context.Users .Where(u => u.UserName.Equals(UserIdentity.SessionUser.UserName, StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (user != null) { user.UserName = txbUsername.Text; user.FullName = txbFullName.Text; user.Address = txbAddress.Text; user.Birthday = dateBirthday.DateTime; user.Gender = _gender; context.SaveChanges(); // cap nhat lai session user UserIdentity.SessionUser.UserName = user.UserName; UserIdentity.SessionUser.FullName = user.FullName; UserIdentity.SessionUser.Address = user.Address; UserIdentity.SessionUser.Birthday = user.Birthday; UserIdentity.SessionUser.Gender = user.Gender; UserIdentity.SessionUser.Role.Name = user.Role.Name; } XtraMessageBox.Show("Edit successfully!", "Success"); this.DialogResult = DialogResult.OK; this.Close(); } }
public void AddSaleUnitToCommodity(string unitName, decimal unitPrice, int commodityId) { var saleUnit = context.Commodities.Find(commodityId)?.SaleUnits; if (saleUnit is null) { System.Windows.Forms.MessageBox.Show("Commodity id not found"); return; } var tmpUnit = saleUnit.FirstOrDefault(s => s.SaleUnitName.Equals(unitName, StringComparison.OrdinalIgnoreCase)); if (tmpUnit is null) { saleUnit.Add(new SaleUnit { SaleUnitName = unitName, SaleUnitPrice = unitPrice, CommodityId = commodityId, }); } else { tmpUnit.SaleUnitPrice = unitPrice; } context.SaveChanges(); }
public string GetCustomerIdByName(string name, PharmacyDbContext db) { if (name == "") { name = "Unknown"; } Customer customer = db.Customer.FirstOrDefault(i => i.Name == name); if (customer != null) { return(customer.Id); } else { customer = new Customer { Id = UniqueNumber.GenerateUniqueNumber(), Name = name, Mobile = txtPhone.Text, CreatedBy = currentUser, CreatedDate = DateTime.Now }; db.Customer.Add(customer); db.SaveChanges(); return(customer.Id); } }
public void Create() { new TestOrganizationUnitsBuilder(_context, _tenantId).Create(); new TestSubscriptionPaymentBuilder(_context, _tenantId).Create(); new TestEditionsBuilder(_context).Create(); _context.SaveChanges(); }
public User Create(User model) { var dal = model.ToDAL(); _db.User.Add(dal); _db.SaveChanges(); return(_db.User.Find(dal.UserId).ToBLL()); }
public void Create() { new DefaultEditionCreator(_context).Create(); new DefaultLanguagesCreator(_context).Create(); new HostRoleAndUserCreator(_context).Create(); new DefaultSettingsCreator(_context).Create(); _context.SaveChanges(); }
public RackViewModel AddRack(PHRMRackModel model) { db.PHRMRack.Add(model); db.SaveChanges(); var result = new RackViewModel() { RackId = model.RackId, Name = model.Name, ParentRackName = (from rack in db.PHRMRack where rack.RackId == model.ParentId select rack.Name).FirstOrDefault(), Description = model.Description, CreatedBy = model.CreatedBy, CreatedOn = model.CreatedOn, }; return(result); }
private void btnPay_Click(object sender, EventArgs e) { PharmacyDbContext db = new PharmacyDbContext(); SaveInvoice(db); db.SaveChanges(); db.Dispose(); MessageBox.Show("Save successful", "Paid!", MessageBoxButtons.OK, MessageBoxIcon.Hand); }
public void TearDown() { dbContext.InvoiceContents.RemoveRange(dbContext.InvoiceContents); dbContext.Invoices.RemoveRange(dbContext.Invoices); dbContext.Users.RemoveRange(dbContext.Users); dbContext.Medications.RemoveRange(dbContext.Medications); dbContext.SaveChanges(); dbContext.Dispose(); }
public ActionResult Create([Bind(Include = "Id,Address,FirstName,LastName,EGN")] Person person) { var found = db.Persons.Where(p => p.EGN == person.EGN).FirstOrDefault(); if (found != null) { ModelState.AddModelError("EGN", "ENG already exists!!!"); } if (ModelState.IsValid) { person.Id = Guid.NewGuid(); db.Persons.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(person)); }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
private void btnSubmit_click(object sender, EventArgs e) { PharmacyDbContext db = new PharmacyDbContext(); SaveInvoice(db); db.SaveChanges(); db.Dispose(); MessageBox.Show("Save successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFields(); }
public ActionResult Create([Bind(Include = "Id,Number,DoneAt,CounterpartyId")] Sell sell) { var found = db.Sells.Where(s => s.Number == sell.Number).FirstOrDefault(); if (found != null) { ModelState.AddModelError("Number", "Number already exists!!!"); } if (ModelState.IsValid) { sell.Id = Guid.NewGuid(); db.Sells.Add(sell); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CounterpartyId = new SelectList(db.Counterparties, "Id", "Stringed", sell.CounterpartyId); return(View(sell)); }
private void UpdateUnitPrice(string medicineName, string rate, DateTime exDate) { PharmacyDbContext db = new PharmacyDbContext(); decimal price = Convert.ToDecimal(rate); Medicine medicine = db.Medicine.FirstOrDefault(x => x.Name == medicineName); medicine.UnitPrice = price; medicine.ExpiredDate = exDate; db.SaveChanges(); db.Dispose(); }
public void NewCommodity(Commodity commodity, CommodityType type) { if (string.IsNullOrWhiteSpace(type.Name)) { type = context.CommodityTypes.First(ct => ct.Name == "Other"); } else if (context.CommodityTypes.Any(t => t.Name.Equals(type.Name))) { type = context.CommodityTypes.First(t => t.Name.Equals(type.Name)); } else { type = context.CommodityTypes.Add(type); } commodity = context.Commodities.Add(commodity); type.Commodities.Add(commodity); context.SaveChanges(); }
private OrganizationUnit CreateOrganizationUnit(string displayName, string code, long?parentId = null) { var organizationUnit = _context.OrganizationUnits.Add(new OrganizationUnit(_tenantId, displayName, parentId) { Code = code }).Entity; _context.SaveChanges(); return(organizationUnit); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
public ActionResult Create([Bind(Include = "Id,Price,Quantity,MedicineId,SellId")] SoldMedicine soldMedicine) { var found = db.Medicines.Find(soldMedicine.MedicineId).AvailableQuantity - soldMedicine.Quantity; if (found < 0) { ModelState.AddModelError("Quantity", "Quantity too low!!!"); } if (ModelState.IsValid) { soldMedicine.Id = Guid.NewGuid(); db.SoldMedicines.Add(soldMedicine); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MedicineId = new SelectList(db.Medicines, "Id", "Name", soldMedicine.MedicineId); ViewBag.SellId = new SelectList(db.Sells, "Id", "Number", soldMedicine.SellId); return(View(soldMedicine)); }
private void btnSubmit_click(object sender, EventArgs e) { PharmacyDbContext db = new PharmacyDbContext(); SaveInvoice(db); db.SaveChanges(); db.Dispose(); MessageBox.Show("Save successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); btnPrint.Enabled = true; txtNote.Text = ""; lvExpense.Items.Clear(); }
public ActionResult Create([Bind(Include = "Id,Address,Name,Code,EIK")] Firm firm) { var found = db.Firms.Where(f => f.EIK == firm.EIK).FirstOrDefault(); if (found != null) { ModelState.AddModelError("EIK", "EIK already exists!!!"); } if (!this.IsRealEIK(firm.EIK)) { ModelState.AddModelError("EIK", "EIK is fake!!!"); } if (ModelState.IsValid) { firm.Id = Guid.NewGuid(); db.Firms.Add(firm); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(firm)); }
public bool Update(Stockpile model) { var dal = model.ToDAL(); try { _db.Stockpile.Update(dal); _db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
private void btnSubmit_click(object sender, EventArgs e) { PharmacyDbContext db = new PharmacyDbContext(); SaveInvoice(db); db.SaveChanges(); db.Dispose(); MessageBox.Show("Save successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); lvPurchaseMedicine.Items.Clear(); txtDiscount.Text = ""; txtDue.Text = ""; txtPaid.Text = ""; txtNote.Text = ""; }
public bool Update(Medicine model) { try { var temp = _db.Medicine.Find(model.Id); temp.Price = model.Price; temp.Name = model.Name ?? temp.Name; _db.Medicine.Update(temp); _db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
private void CreateLookupIfNotExist(Lookup lookup) { // check if lookup with the lookup type id does exist, and add if it didn't exist. var defaultLookupType = _context.Lookups.IgnoreQueryFilters().FirstOrDefault(t => t.Id == lookup.Id); if (defaultLookupType != null) { return; } _context.Database.OpenConnection(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Lookups ON"); _context.Lookups.Add(lookup); _context.SaveChanges(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Lookups OFF"); _context.Database.CloseConnection(); }