public JResult InsInventario(InventarioViewModel model) { try { FACT_INVENTARIO dbItem = new FACT_INVENTARIO { Id = model.Id, ProductoId = model.ProductoId, Existencias = model.Existencias, Estregistro = 1, }; db.FACT_INVENTARIO.Attach(dbItem); db.Entry(dbItem).State = EntityState.Added; db.SaveChanges(); model.Id = dbItem.Id; model.Estregistro = 1; jresult.Data = model; #region Salida Generica OK return(jresult.SetOk("Registro creado correctamente")); #endregion } #region Salida generica para errores catch (Exception ex) { return(jresult.SetError(ex, "Error registrando datos", this.GetType().Name)); } #endregion }
public JResult InsCliente(ClienteViewModel model) { try { FACT_CLIENTE dbItem = new FACT_CLIENTE { Id = model.Id, Documento = model.Documento.ToUpper(), Nombres = model.Nombres.ToUpper(), FechaNacimiento = model.FechaNacimiento, Telefono = model.Telefono, Direccion = model.Direccion.ToUpper(), Estregistro = 1, }; db.FACT_CLIENTE.Attach(dbItem); db.Entry(dbItem).State = EntityState.Added; db.SaveChanges(); model.Id = dbItem.Id; model.Estregistro = 1; jresult.Data = model; #region Salida Generica OK return(jresult.SetOk("Registro creado correctamente")); #endregion } #region Salida generica para errores catch (Exception ex) { return(jresult.SetError(ex, "Error registrando datos", this.GetType().Name)); } #endregion }
public Task <IdentityResult> CreateAsync(AplicationRole role, CancellationToken cancellationToken) { try { if (cancellationToken != null) { cancellationToken.ThrowIfCancellationRequested(); } if (role == null) { throw new ArgumentNullException(nameof(role)); } var roleEntity = GetRoleEntity(role); _db.Roles.Add(roleEntity); _db.SaveChanges(); return(Task.FromResult(IdentityResult.Success)); } catch (Exception ex) { return(Task.FromResult(IdentityResult.Failed(new IdentityError { Code = ex.Message, Description = ex.Message }))); } }
public JResult InsProducto(ProductoViewModel model) { try { FACT_PRODUCTO dbItem = new FACT_PRODUCTO { Id = model.Id, Codigo = model.Codigo.ToUpper(), Nombre = model.Nombre.ToUpper(), Valor = model.Valor, Estregistro = 1 }; db.FACT_PRODUCTO.Attach(dbItem); db.Entry(dbItem).State = EntityState.Added; db.SaveChanges(); model.Id = dbItem.Id; model.Estregistro = 1; jresult.Data = model; #region Salida Generica OK return(jresult.SetOk("Registro creado correctamente")); #endregion } #region Salida generica para errores catch (Exception ex) { return(jresult.SetError(ex, "Error registrando datos", this.GetType().Name)); } #endregion }
public JResult InsFactura(FacturaViewModel model) { try { FACT_FACTURA dbItem = new FACT_FACTURA { Id = model.Id, ClienteId = model.ClienteId, Fecha = model.Fecha, //utilidades.ObtenerFechaDesdeString(model.Fecha), Total = model.Total, Estregistro = 1, }; db.FACT_FACTURA.Attach(dbItem); db.Entry(dbItem).State = EntityState.Added; db.SaveChanges(); model.Id = dbItem.Id; model.Estregistro = 1; jresult.Data = model; #region Salida Generica OK return(jresult.SetOk("Registro creado correctamente")); #endregion } #region Salida generica para errores catch (Exception ex) { return(jresult.SetError(ex, "Error registrando datos", this.GetType().Name)); } #endregion }
public ActionResult RevokeGroup(int GroupId, string UserId) { tblUserGroup tblUserGroups = db.tblUserGroup.FirstOrDefault(s => s.FK_Group == GroupId && s.FK_User == UserId); if (tblUserGroups != null) { db.tblUserGroup.Remove(tblUserGroups); db.SaveChanges(); } return(RedirectToAction("Details", new { id = UserId })); }
public ActionResult Add(tbl_SanPhams model, HttpPostedFileBase image) { Poco_Page_ThemSanPham item = new Poco_Page_ThemSanPham(); if (string.IsNullOrEmpty(model.MoTaDai)) { model.MoTaDai = string.Empty; } if (string.IsNullOrEmpty(model.MoTaNgan)) { model.MoTaNgan = string.Empty; } model.DaXoa = false; model.SoLanXem = 0; model.SoLanMua = 0; model.NgayNhap = DateTime.Now; using (ModelEntities ctx = new ModelEntities()) { ctx.tbl_SanPhams.Add(model); ctx.SaveChanges(); item.DanhSachLoaiSanPham = ctx.tbl_LoaiSanPhams.ToList(); item.DanhSachNhaCungCap = ctx.tbl_NhaSanXuats.ToList(); if (image != null && image.ContentLength > 0) { //Tao folder chua hinh string patch1 = Server.MapPath("~/image"); string tagetdir = Path.Combine(patch1, model.SanPhamID.ToString()); Directory.CreateDirectory(tagetdir); //Copy hinh string mainThumn = Path.Combine(tagetdir, "main_thumn.jpg"); image.SaveAs(mainThumn); } return(View(item)); } }
public ActionResult Register(Poco_DangKy item) { if (!ModelState.IsValid) { return(View(3)); } tbl_NguoiSuDungs obj = new tbl_NguoiSuDungs(); obj.TenDangNhap = item.TenDangNhap; using (ModelEntities ctx = new ModelEntities()) { if (ctx.tbl_NguoiSuDungs.Any(p => p.TenDangNhap == item.TenDangNhap)) { return(View(2)); } } obj.MatKhau = StringUtils.Md5(item.MatKhau); obj.GioiTinh = item.GioiTinh; obj.NgaySinh = DateTime.ParseExact(item.NgaySinh, "dd/MM/yyyy", null); obj.DiaChi = item.DiaChi; obj.SoDienThoai = item.SoDienThoai; obj.TenNguoiSuDung = item.HoTen; obj.Quyen = 0; obj.DaXoa = false; using (ModelEntities ctx = new ModelEntities()) { ctx.tbl_NguoiSuDungs.Add(obj); ctx.SaveChanges(); } return(View(0)); }
public ActionResult SetGiaoHang(int?id, bool edit = false) { if (!id.HasValue) { if (edit == true) { return(RedirectToAction("Edit", new { id = id })); } return(RedirectToAction("Index")); } else { using (ModelEntities ctx = new ModelEntities()) { tbl_PhieuOrders itemFind = ctx.tbl_PhieuOrders.Where(p => p.PhieuOrderID == id.Value).FirstOrDefault(); itemFind.TinhTrangGiaoHang = true; ctx.SaveChanges(); if (edit == true) { return(RedirectToAction("Edit", new { id = id })); } return(RedirectToAction("Index")); } } }
public ActionResult Edit(tbl_SanPhams item, HttpPostedFileBase image) { using (ModelEntities ctx = new ModelEntities()) { tbl_SanPhams itemFind = ctx.tbl_SanPhams.Where(p => p.SanPhamID == item.SanPhamID).FirstOrDefault(); if (itemFind == null) { return(RedirectToAction("Index")); } itemFind.TenSanPham = item.TenSanPham; itemFind.Gia = item.Gia; itemFind.MoTaNgan = item.MoTaNgan; itemFind.MoTaDai = item.MoTaDai; itemFind.NongDo = item.NongDo; itemFind.SoLuong = item.SoLuong; itemFind.TinhTrang = item.TinhTrang; itemFind.LoaiSanPhamID = item.LoaiSanPhamID; itemFind.NhaSanXuatID = item.NhaSanXuatID; if (image != null && image.ContentLength > 0) { //Tao folder chua hinh string patch1 = Server.MapPath("~/image"); string tagetdir = Path.Combine(patch1, item.SanPhamID.ToString()); Directory.CreateDirectory(tagetdir); //Copy hinh string mainThumn = Path.Combine(tagetdir, "main_thumn.jpg"); image.SaveAs(mainThumn); } ctx.SaveChanges(); return(RedirectToAction("Edit", new { id = item.SanPhamID })); } }
public bool CreatePerson(tb_person _person) { using (database = new ModelEntities()) { database.tb_person.Add(_person); database.SaveChanges(); return(true); } }
public static void BusEnded(List <DTOPath> path) { using (ModelEntities db = new ModelEntities()) { db.StudentInBus.ToList(). ForEach(s => s.didCome = path.Where(p => p.StudentInBusId == s.StudentInBusId).First().DidCome); db.SaveChanges(); } }
public JResult InsFacturaDetalle(FacturaDetalleViewModel model) { try { ProductoBL productoBL = new ProductoBL(); var producto = productoBL.GetProducto(model.InventarioId); FACT_FACTURA_DETALLE dbItem = new FACT_FACTURA_DETALLE { Id = model.Id, FacturaId = model.FacturaId, InventarioId = model.InventarioId, Cant = model.Cant, Subtotal = producto.Data.Valor * model.Cant, Estregistro = 1, }; db.FACT_FACTURA_DETALLE.Attach(dbItem); db.Entry(dbItem).State = EntityState.Added; db.SaveChanges(); var result = UpdTotalFactura(model.FacturaId); if (!result.Success) { return(jresult.SetError(null, "Error actualizando total factura", this.GetType().Name)); } model.Id = dbItem.Id; model.Estregistro = 1; jresult.Data = model; #region Salida Generica OK return(jresult.SetOk("Registro creado correctamente")); #endregion } #region Salida generica para errores catch (Exception ex) { return(jresult.SetError(ex, "Error registrando datos", this.GetType().Name)); } #endregion }
public bool RemovePatient(string patientID) { using (ModelEntities database = new ModelEntities()) { tb_patient patient = database.tb_patient.SingleOrDefault(p => p.PatientID == patientID); database.tb_patient.Remove(patient); database.SaveChanges(); return(true); } }
//[MultipleButton(Name = "action", Argument = "Delete")] public ActionResult Delete(int?id) { using (ModelEntities ctx = new ModelEntities()) { tbl_SanPhams itemFind = ctx.tbl_SanPhams.Where(p => p.SanPhamID == id).FirstOrDefault(); itemFind.DaXoa = true; ctx.SaveChanges(); return(RedirectToAction("Index")); } }
public void SaveChanges() { try { _context.SaveChanges(); } catch (DbEntityValidationException e) { throw; } }
public ActionResult Add(tbl_LoaiSanPhams item) { using (ModelEntities ctx = new ModelEntities()) { tbl_LoaiSanPhams itemAdd = new tbl_LoaiSanPhams(); itemAdd.TenLoaiSanPham = item.TenLoaiSanPham; itemAdd.DaXoa = !item.DaXoa; ctx.tbl_LoaiSanPhams.Add(itemAdd); ctx.SaveChanges(); return(View()); } }
public ActionResult Add(tbl_NhaSanXuats item) { using (ModelEntities ctx = new ModelEntities()) { tbl_NhaSanXuats itemAdd = new tbl_NhaSanXuats(); itemAdd.TenNhaSanXuat = item.TenNhaSanXuat; itemAdd.DaXoa = !item.DaXoa; ctx.tbl_NhaSanXuats.Add(itemAdd); ctx.SaveChanges(); return(View()); } }
public EntryManager() { Mapper.Initialize(x => { x.CreateMap <Entry, Entryvm>(); x.CreateMap <Entryvm, Entry>(); x.CreateMap <Archive, Archivevm>(); }); var last = m.Archives.Single(x => x.DateAdded.Month + 1 == (DateTime.Now.Month)); if (last == null) { m.Archives.Add( new Archive { Name = DateTime.Now.ToString("MMMM") + " " + DateTime.Now.Year.ToString(), DateAdded = DateTime.Now }); m.SaveChanges(); } }
public EntryManager() { Mapper.Initialize(x => { x.CreateMap <Entry, Entryvm>(); x.CreateMap <Entryvm, Entry>(); x.CreateMap <Archive, Archivevm>(); }); foreach (var item in m.Archives) { if (item.DateAdded.Month < DateTime.Now.Month) { m.Archives.Add( new Archive { Name = DateTime.Now.ToString("MMMM") + " " + DateTime.Now.Year.ToString(), DateAdded = DateTime.Now }); m.SaveChanges(); } } }
public bool AddText(Text modeltext) { var text = new Texts(); try { text.Title = modeltext.Title; text.Content = modeltext.Content; text.TextTypeID = modeltext.TextTypeID; text.UserID = modeltext.UserID; text.IsRelease = modeltext.IsRelease == null ? false:modeltext.IsRelease.Value; text.Release_date = DateTime.Now; db.Texts.Add(text); db.SaveChanges(); Logger.SendLog("TextRepository/AddText", modeltext, false, LogTypes.Response); return(true); } catch (Exception ex) { Logger.SendLog("TextRepository/AddText", modeltext + " " + ex.ToString(), true, LogTypes.Response); return(false); } }
public ActionResult RestoreCat(int?id) { using (ModelEntities ctx = new ModelEntities()) { tbl_LoaiSanPhams item2 = ctx.tbl_LoaiSanPhams.Where(p => p.LoaiSanPhamID == id).FirstOrDefault(); if (item2 != null) { item2.DaXoa = false; ctx.SaveChanges(); return(RedirectToAction("Edit", new { id = id })); } return(RedirectToAction("Index")); } }
public ActionResult Edit(tbl_LoaiSanPhams item) { using (ModelEntities ctx = new ModelEntities()) { tbl_LoaiSanPhams item2 = ctx.tbl_LoaiSanPhams.Where(p => p.LoaiSanPhamID == item.LoaiSanPhamID).FirstOrDefault(); if (item2 != null) { item2.TenLoaiSanPham = item.TenLoaiSanPham; ctx.SaveChanges(); return(View(item2)); } return(RedirectToAction("Index")); } }
public ActionResult DeleteFac(int?id) { using (ModelEntities ctx = new ModelEntities()) { tbl_NhaSanXuats item2 = ctx.tbl_NhaSanXuats.Where(p => p.NhaSanXuatID == id.Value).FirstOrDefault(); if (item2 != null) { item2.DaXoa = true; ctx.SaveChanges(); return(RedirectToAction("Edit", new { id = id })); } return(RedirectToAction("Index")); } }
public ActionResult Edit(tbl_NhaSanXuats item) { using (ModelEntities ctx = new ModelEntities()) { tbl_NhaSanXuats item2 = ctx.tbl_NhaSanXuats.Where(p => p.NhaSanXuatID == item.NhaSanXuatID).FirstOrDefault(); if (item2 != null) { item2.TenNhaSanXuat = item.TenNhaSanXuat; ctx.SaveChanges(); return(RedirectToAction("Edit", new { id = item2.NhaSanXuatID })); } return(RedirectToAction("Index")); } }
public bool AddUser(User modelUser) { var users = new Users(); try { users.ID = Guid.NewGuid(); users.Name = modelUser.Name; users.Surname = modelUser.Surname; users.Email = modelUser.Email; users.Username = modelUser.Username; users.Password = modelUser.Password; users.RoleID = Convert.ToInt32(RoleTypes.User); db.Users.Add(users); db.SaveChanges(); Logger.SendLog("UserRepository/AddUser", modelUser, false, LogTypes.Response); return(true); } catch (Exception ex) { Logger.SendLog("UserRepository/AddUser", modelUser + " " + ex.ToString(), true, LogTypes.Response); return(false); } }
public static void SendLog(string methodname, object data, bool?isError, LogTypes?logtype) { using (var db = new ModelEntities()) { var logs = new Logs(); logs.MethodName = methodname; logs.Data = data.ToString(); logs.IsError = isError == null? false:isError.Value; logs.LogTypeID = logtype == null?Convert.ToInt32(LogTypes.Response) : Convert.ToInt32(logtype.Value); logs.CreatedDate = DateTime.Now; db.Logs.Add(logs); db.SaveChanges(); } }
public ActionResult SetDelete(int?id) { if (!id.HasValue) { return(RedirectToAction("Index")); } else { using (ModelEntities ctx = new ModelEntities()) { tbl_PhieuOrders itemFind = ctx.tbl_PhieuOrders.Where(p => p.PhieuOrderID == id.Value).FirstOrDefault(); itemFind.DaXoa = true; ctx.SaveChanges(); return(RedirectToAction("Index")); } } }
public bool UpdatePerson(tb_person _person) { using (database = new ModelEntities()) { tb_person patient = database.tb_person.SingleOrDefault(p => p.PersonID == _person.PersonID); patient.FullName = _person.FullName; patient.Birthday = _person.Birthday; patient.Address = _person.Address; patient.Gender = _person.Gender; patient.MobilePhone = _person.MobilePhone; patient.Email = _person.Email; patient.Marital = _person.Marital; patient.Note = _person.Note; database.SaveChanges(); return(true); } }
public ActionResult RevokeAction(int GroupId, string ActionName) { tblGroupActions tblGroupActions = db.tblGroupActions.FirstOrDefault(s => s.FK_Group == GroupId && s.ActionName == ActionName); if (tblGroupActions != null) { db.tblGroupActions.Remove(tblGroupActions); db.SaveChanges(); } return(RedirectToAction("Details", new { id = GroupId })); }