public string changeStore2(StoreViewModel model) { ApiReply reply = new ApiReply() { result = 1 }; var currentUser = (PersonalizedIdentity)User.Identity; try { using (AlmacenDBEntities db = new AlmacenDBEntities()) { var oUser = (from us in db.user where currentUser.id == us.id select us).FirstOrDefault(); var oStore = (from st in db.user_store where model.id == st.id_store && oUser.id == st.id_user select st).FirstOrDefault(); if (oStore == null) { reply.message = "Error de Sucursal"; return(JsonConvert.SerializeObject(reply)); } oUser.id_defaultStore = model.id; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } reply.result = 0; reply.message = "Cambio de Sucursal con exito"; return(JsonConvert.SerializeObject(reply)); } catch (Exception ex) { reply.message = "Error al Actualizar Almacen"; return(JsonConvert.SerializeObject(reply)); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var current_user = (PersonalizedIdentity)User.Identity; using (AlmacenDBEntities db = new AlmacenDBEntities()) { var oUser = (from us in db.user where us.id == current_user.id select us).FirstOrDefault(); var oStore = (from st in db.store where oUser.id_defaultStore == st.id select st).FirstOrDefault(); ViewBag.name_user = oUser.first_name; ViewBag.id_user = oUser.id; ViewBag.id_store = oStore.id; ViewBag.name_store = oStore.name; } }
// GET: Provider/Create public ActionResult CreateProvider() { try { List <CountryViewModel> countries; using (AlmacenDBEntities db = new AlmacenDBEntities()) { countries = (from co in db.country select new CountryViewModel { id = co.id, name = co.name }).ToList(); } return(View(countries)); } catch (Exception ex) { return(View("Error", "Shared")); } }
public ActionResult changeStore(StoreViewModel model) { var currentUser = (PersonalizedIdentity)User.Identity; try { using (AlmacenDBEntities db = new AlmacenDBEntities()) { var oUser = (from us in db.user where currentUser.id == us.id select us).FirstOrDefault(); oUser.id_defaultStore = model.id; db.Entry(oUser).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index", "Home")); } catch (Exception ex) { return(View("Error")); } }
public ActionResult CreateProvider(ProviderViewModel model) { try { using (AlmacenDBEntities db = new AlmacenDBEntities()) { provider oProvider = new provider(); oProvider.name = model.name; oProvider.phone = model.phone; oProvider.rfc = model.rfc; oProvider.id_location = model.location; oProvider.address = model.address; db.provider.Add(oProvider); db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: Provider public ActionResult Index_Provider() { try { List <ProviderViewModel> oProvider; using (AlmacenDBEntities db = new AlmacenDBEntities()) { oProvider = (from pro in db.provider select new ProviderViewModel { id = pro.id, name = pro.name, phone = pro.phone, address = pro.address, rfc = pro.rfc }).ToList(); } return(View(oProvider)); } catch (Exception ex) { return(RedirectToAction("ErrorPage", "Error")); } }
public ApiReply getStore(int id_user, int id_store) { ApiReply reply = new ApiReply(); reply.result = 0; try { using (AlmacenDBEntities db = new AlmacenDBEntities()) { List <StoreViewModel> oStore = (from st in db.store from su in db.user_store where su.id_user == id_user && st.id == su.id_store && st.id != id_store select new StoreViewModel { id = st.id, name = st.name }).ToList(); //Envia respuesta a usuario reply.result = 0; if (oStore.Count > 0) { reply.message = "Tiendas disponibles"; reply.data = oStore; } else { reply.message = "Solo cuentas con el almacen actual"; } } } catch (Exception ex) { reply.message = "Ocurrio un error en el servidor"; } return(reply); }