public async Task <ActionResult> Create(UserView view) { //Sirve para poder ver errores en el ingreso de datos //var errors = ModelState.Where(x => x.Value.Errors.Count > 0) // .Select(x => new { x.Key, x.Value.Errors }) // .ToArray(); if (ModelState.IsValid) { var pic = string.Empty; var folder = "~/Content/Users"; if (view.PhotoFile != null) { pic = FilesHelper.UploadPhoto(view.PhotoFile, folder); pic = string.Format("{0}/{1}", folder, pic); } var user = this.ToUser(view, pic); this.db.Users.Add(user); await this.db.SaveChangesAsync(); UsersHelper.CreateUserASP(user.UserName, user.AspRoles); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", view.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", view.DistrictId); ViewBag.MainWarehouseId = new SelectList(db.MainWarehouses, "MainWarehouseId", "Name"); ViewBag.userRoles = SelectUserRolers(); return(View(view)); }
public async Task <ActionResult> Create(CompanyView view) { if (ModelState.IsValid) { var pic = string.Empty; var folder = "~/Content/Companies"; if (view.LogoFile != null) { pic = FilesHelper.UploadPhoto(view.LogoFile, folder); pic = string.Format("{0}/{1}", folder, pic); } var company = this.ToCompany(view, pic); this.db.Companies.Add(company); await this.db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", view.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", view.DistrictId); return(View(view)); }
// GET: Customers/Create public ActionResult Create() { ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name"); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name"); var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); var customer = new Customer { CompanyId = user.CompanyId, }; return(View(customer)); }
public async Task <ActionResult> Edit(Customer customer) { if (ModelState.IsValid) { db.Entry(customer).State = EntityState.Modified; await db.SaveChangesAsync(); // TODO: Validate when the customer email change return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", customer.DistrictId); return(View(customer)); }
public async Task <ActionResult> Create(Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); await db.SaveChangesAsync(); UsersHelper.CreateUserASP(customer.UserName, "Customer"); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", customer.DistrictId); return(View(customer)); }
// GET: Customers/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var customer = await db.Customers.FindAsync(id); if (customer == null) { return(HttpNotFound()); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", customer.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", customer.DistrictId); return(View(customer)); }
public async Task <ActionResult> Create(Warehouse warehouse) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { db.Warehouses.Add(warehouse); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", warehouse.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", warehouse.DistrictId); ViewBag.UserId = new SelectList(CombosHelper.GetUsers(user.CompanyId), "UserId", "UserName", warehouse.UserId); ViewBag.MainWarehouseId = new SelectList(db.MainWarehouses, "MainWarehouseId", "Name", warehouse.MainWarehouseId); return(View(warehouse)); }
// GET: Warehouses/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); var warehouse = new Warehouse { CompanyId = user.CompanyId, }; //TODO still i don´t created the getmainwarehouses ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name"); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name"); ViewBag.UserId = new SelectList(CombosHelper.GetUsers(user.CompanyId), "UserId", "UserName"); ViewBag.MainWarehouseId = new SelectList(db.MainWarehouses, "MainWarehouseId", "Name"); //var mainwarehouse = new MainWarehouse { MainWarehouseId = user.MainWarehouseId, }; return(View(warehouse)); }
// GET: Users/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } var userlog = new UserView { CompanyId = user.CompanyId }; ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name"); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name"); ViewBag.MainWarehouseId = new SelectList(CombosHelper.GetMainWarehouses(user.CompanyId), "MainWarehouseId", "Name"); ViewBag.userRoles = SelectUserRolers(); return(View(userlog)); }
// GET: Companies/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var company = await this.db.Companies.FindAsync(id); if (company == null) { return(HttpNotFound()); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", company.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", company.DistrictId); var view = this.ToView(company); return(View(company)); }
// GET: Warehouses/Edit/5 public async Task <ActionResult> Edit(int?id) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var warehouse = await db.Warehouses.FindAsync(id); if (warehouse == null) { return(HttpNotFound()); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", warehouse.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", warehouse.DistrictId); ViewBag.UserId = new SelectList(CombosHelper.GetUsers(user.CompanyId), "UserId", "UserName", warehouse.UserId); ViewBag.MainWarehouseId = new SelectList(db.MainWarehouses, "MainWarehouseId", "Name", warehouse.MainWarehouseId); return(View(warehouse)); }
public async Task <ActionResult> Edit(UserView view) { if (ModelState.IsValid) { var pic = view.Photo; var folder = "~/Content/Users"; if (view.PhotoFile != null) { pic = FilesHelper.UploadPhoto(view.PhotoFile, folder); pic = string.Format("{0}/{1}", folder, pic); } var db2 = new LocalDataContext(); var currentUser = db2.Users.Find(view.UserId); if (currentUser.UserName != view.UserName) { UsersHelper.UpdateUserName(currentUser.UserName, view.UserName, view.AspRoles); } db2.Dispose(); var user = this.ToUserEdit(view, pic); this.db.Entry(user).State = EntityState.Modified; var userLast = db.Users.Where(u => u.UserName == view.UserName).FirstOrDefault(); UsersHelper.UpdateUserRole(currentUser.UserName, userLast.AspRoles, user.AspRoles); await this.db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", view.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", view.DistrictId); ViewBag.MainWarehouseId = new SelectList(db.MainWarehouses, "MainWarehouseId", "Name", view.MainWarehouseId); ViewBag.userRoles = SelectUserRolers(); return(View(view)); }
// GET: Users/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = await this.db.Users.FindAsync(id); if (user == null) { return(HttpNotFound()); } ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name", user.DistrictId); ViewBag.MainWarehouseId = new SelectList(db.MainWarehouses, "MainWarehouseId", "Name", user.MainWarehouseId); ViewBag.userRoles = SelectUserRolers(); var view = this.ToView(user); return(View(view)); }
// GET: Companies/Create public ActionResult Create() { ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name"); ViewBag.DistrictId = new SelectList(CombosHelper.GetDistricts(), "DistrictId", "Name"); return(View()); }