public static bool Modificar(NotasCredito nota) { bool paso = false; try { Contex contex = new Contex(); var estudiante = BLL.EstudiantesBLL.Buscar(nota.EstudianteID); var notas = Buscar(nota.NotasID); estudiante.Monto -= notas.Monto; BLL.EstudiantesBLL.Modificar(estudiante); contex.Entry(nota).State = EntityState.Modified; estudiante.Monto += nota.Monto; BLL.EstudiantesBLL.Modificar(estudiante); if (contex.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } return(paso); }
public void EditSupplier(EditSupplierBM model, int userId) { var supplier = Mapper.Map <Supplier>(model); Contex.Entry(supplier).State = EntityState.Modified; Contex.SaveChanges(); this.AddLog(userId, Operation.Edit); }
public void EditCustomer(EditCustomerBM customerBM) { var customer = Contex.Customers.Find(customerBM.Id); var age = DateTime.Today.Year - customerBM.BirthDate.Year; if (age > 18) { customer.IsYoungDriver = false; } else { customer.IsYoungDriver = true; } customer.Name = customerBM.Name; customer.BirthDate = customerBM.BirthDate; Contex.Entry(customer).State = EntityState.Modified; Contex.SaveChanges(); }
private void SaveToDataBase() { // string t = "0"; try { Flag = 0; // var entityConnectionString = Contex.BuildEntityConnection (@"Data Source=192.168.0.17\sql2014;Initial Catalog=Personel;User ID=sa;Password=@110;Connection Timeout=60;"); //string entityConnectionString=@"Data Source=192.168.0.17\sql2014;Initial Catalog=Personel;User ID=sa;Password=@110;Connection Timeout=60;"; var setting = GetSetting(); var entityConnectionString = Contex.BuildEntityConnection(setting.DataSource, setting.Instance, setting.InitialCatalog, setting.UserId, setting.Password); using (var db = new WpfManage.DAL.Contex()) { using (var dbs = new Contex()) { WpfManage.Model.Personel person = new WpfManage.Model.Personel(); person.FullName = TextBoxFullName.Text.Trim(); person.NCode = TextBoxNationalCode.Text.Trim(); person.PersonelNumber = TextBoxPersonelNo.Text.Trim(); person.Tellephone = TextBoxTellephon.Text.Trim(); person.Address = TextBoxAddres.Text.Trim(); person.RfidCard = TextBoxRfidCard.Text.Trim(); person.NameFather = TextBoxFather.Text.Trim(); //var TextRfid = dbs.memberMap.Single(x => x.RfidCard=="").FirstOrDefault(); // var Rfid = dbs.memberMap.Select(x => x.RfidCard); //اگر مقداری بعنوان عکس توسط کاربر انتخاب نشده بود if (ConvertImageToString == null) { if (Flag == 0) { dbs.Entry(person).State = EntityState.Added; dbs.memberMap.Add(person); dbs.SaveChanges(); MessageBox.Show("اطلاعات با موفقیت ثبت گردید"); //bool hasNationalCode = dbs.memberMap.Any(cus => cus.NCode == TextBoxNationalCode.Text); ////اگر کد ملی در جدول وجود نداشت //if (hasNationalCode==false) //{ // dbs.Entry(person).State = EntityState.Added; // dbs.memberMap.Add(person); // // dbs.SaveChanges(); //} ////اگر کد ملی در دیتا بیس ار قبل ذخیره شده بود //if (hasNationalCode == true) //{ // MessageBox.Show("شماره کد ملی می بایست مقداری منحصر بفرد باشد"); // return; //} TextBoxFullName.Text = ""; TextBoxNationalCode.Text = ""; TextBoxPersonelNo.Text = ""; TextBoxTellephon.Text = ""; TextBoxAddres.Text = ""; TextBoxRfidCard.Text = ""; TextBoxFather.Text = ""; Image_Play.Visibility = Visibility.Visible; Image_SnapShot.Source = null; //var result = (from r in dbs.memberMap.ToList() // select r).ToList(); //DataGridPersonel.ItemsSource = result; MethodFillGrid(); } } //اگر کاربر عکسی را انتخاب کرده بود if (ConvertImageToString != null) { if (Flag == 0) { dbs.Entry(person).State = EntityState.Added; dbs.memberMap.Add(person); //تبدیل عکس به بیس 64 و ذخیره ان در دیتا بیس byte[] imageArray = System.IO.File.ReadAllBytes(ConvertImageToString); string base64ImageRepresentation = Convert.ToBase64String(imageArray); person.Image = base64ImageRepresentation; // dbs.SaveChanges(); MessageBox.Show("اطلاعات با موفقیت ثبت گردید"); TextBoxFullName.Text = ""; TextBoxNationalCode.Text = ""; TextBoxPersonelNo.Text = ""; TextBoxTellephon.Text = ""; TextBoxAddres.Text = ""; TextBoxRfidCard.Text = ""; TextBoxFather.Text = ""; Image_Play.Visibility = Visibility.Visible; Image_SnapShot.Source = null; //var result = (from r in dbs.memberMap.ToList() // select r).ToList(); //DataGridPersonel.ItemsSource = result; MethodFillGrid(); } } MethodFillGrid(); // Image_SnapShot.Source = null; //var result1 = (from r in dbs.memberMap.ToList() // select r).ToList(); //DataGridPersonel.ItemsSource = result1; } } } catch { MessageBox.Show("خطا در ارتباط"); } }
public ActionResult Edit(HttpPostedFileBase simage, HttpPostedFileBase limage, Product product) { //Product p = db.products.Find(product.ProductId); //ViewBag.ok = p.Simage; //return View(); if (ModelState.IsValid) { Random r = new Random(); if ((simage != null && simage.ContentLength > 0) && (limage != null && limage.ContentLength > 0)) { try { string filename = "_" + RandomString(10) + Path.GetFileName(simage.FileName); string path = Path.Combine(Server.MapPath("~/PRODUCT_IMG"), filename); simage.SaveAs(path); product.Simage = "/PRODUCT_IMG/" + filename; string filename1 = "_" + RandomString(10) + Path.GetFileName(limage.FileName); string path1 = Path.Combine(Server.MapPath("~/PRODUCT_IMG"), filename); limage.SaveAs(path1); product.Limage = "/PRODUCT_IMG/" + filename; ViewBag.limage = "File uploaded successfully"; } catch (Exception ex) { ViewBag.simage = "ERROR:" + ex.Message.ToString(); } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = product.ProductName + " successfully Updated"; return(RedirectToAction("Index")); } else if ((simage != null && simage.ContentLength > 0) && (limage == null)) { try { string filename = "_" + RandomString(10) + Path.GetFileName(simage.FileName); string path = Path.Combine(Server.MapPath("~/PRODUCT_IMG"), filename); simage.SaveAs(path); product.Simage = "/PRODUCT_IMG/" + filename; product.Limage = Session["limage"].ToString(); ViewBag.limage = "File uploaded successfully"; } catch (Exception ex) { ViewBag.simage = "ERROR:" + ex.Message.ToString(); } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = product.ProductName + " successfully Updated"; return(RedirectToAction("Index")); } else if ((simage == null) && (limage != null && limage.ContentLength > 0)) { try { product.Simage = Session["simage"].ToString(); string filename1 = "_" + RandomString(10) + Path.GetFileName(limage.FileName); string path1 = Path.Combine(Server.MapPath("~/PRODUCT_IMG"), filename1); limage.SaveAs(path1); product.Limage = "/PRODUCT_IMG/" + filename1; ViewBag.limage = "File uploaded successfully"; } catch (Exception ex) { ViewBag.simage = "ERROR:" + ex.Message.ToString(); } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = product.ProductName + " successfully Updated"; return(RedirectToAction("Index")); } else { product.Simage = Session["simage"].ToString(); product.Limage = Session["limage"].ToString(); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); TempData["message"] = product.ProductName + " successfully Updated"; return(RedirectToAction("Index")); } } return(View()); }