Esempio n. 1
0
        public ActionResult AddProduct(AddProductView view)
        {
            var user = db.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                var ordetailtmp = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name && odt.ProductId == view.ProductId).FirstOrDefault();
                if (ordetailtmp == null)
                {
                    var product = db.Products.Find(view.ProductId);
                    ordetailtmp = new OrderDetailTmp
                    {
                        Description = product.Description,
                        Price       = product.Price,
                        ProductId   = product.ProductId,
                        Quantity    = view.Quantity,
                        TaxRate     = product.Tax.Rate,
                        UserName    = User.Identity.Name,
                    };
                    db.OrderDetailTmps.Add(ordetailtmp);
                }
                else
                {
                    ordetailtmp.Quantity       += view.Quantity;
                    db.Entry(ordetailtmp).State = EntityState.Modified;
                }
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }
            ViewBag.ProductId = new SelectList(CombosHelper.GetProducts(user.CompanyId, false), "ProductId", "Description");
            return(PartialView());
        }
Esempio n. 2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                UsersHelper.CreateUserASP(user.UserName, "User");
                if (user.PhotoFile != null)
                {
                    var folder   = "~/Content/Users";
                    var file     = string.Format("{0}.jpg", user.UserId);
                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);
                    if (response)
                    {
                        var pic = string.Format("{0}/{1}.jpg", folder, user.UserId);
                        user.Photo           = pic;
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
Esempio n. 3
0
        public ActionResult Create(Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                if (product.ImageFile != null)
                {
                    var folder   = "~/Content/Products";
                    var file     = string.Format("{0}.jpg", product.ProductId);
                    var response = FilesHelper.UploadPhoto(product.ImageFile, folder, file);
                    if (response)
                    {
                        var pic = string.Format("{0}/{1}.jpg", folder, product.ProductId);
                        product.Image           = pic;
                        db.Entry(product).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Description", product.CategoryId);
            ViewBag.CompanyId  = new SelectList(db.Companies, "CompanyId", "Name", product.CompanyId);
            ViewBag.TaxId      = new SelectList(db.Taxes, "TaxId", "Description", product.TaxId);
            return(View(product));
        }
Esempio n. 4
0
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();



                if (company.LogoFile != null)
                {
                    var folder   = "~/Content/Logos";
                    var file     = string.Format("{0}.jpg", company.CompanyId);
                    var response = FilesHelper.UploadPhoto(company.LogoFile, folder, file);
                    if (response)
                    {
                        var pic = string.Format("{0}/{1}.jpg", folder, company.CompanyId);
                        company.Logo            = pic;
                        db.Entry(company).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelper.GetCities(company.DepartmentId), "CityId", "Name", company.CityId);
            ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", company.DepartmentId);
            return(View(company));
        }
Esempio n. 5
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserId)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 6
0
 public ActionResult Edit([Bind(Include = "CityId,Name,DepartmentId")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             if (ex.InnerException != null &&
                 ex.InnerException.InnerException != null &&
                 ex.InnerException.InnerException.Message.Contains("_Index"))
             {
                 ModelState.AddModelError(string.Empty, "The are record we the same name in department");
             }
             else
             {
                 ModelState.AddModelError(string.Empty, ex.Message);
             }
         }
     }
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", city.DepartmentId);
     return(View(city));
 }
 public ActionResult Edit([Bind(Include = "DepartmentId,Name")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             if (ex.InnerException != null &&
                 ex.InnerException.InnerException != null &&
                 ex.InnerException.InnerException.Message.Contains("_Index"))
             {
                 ModelState.AddModelError(string.Empty, "The are record we the same name");
             }
             else
             {
                 ModelState.AddModelError(string.Empty, ex.Message);
             }
         }
     }
     return(View(department));
 }
Esempio n. 8
0
 public ActionResult Edit(Customer customer)
 {
     if (ModelState.IsValid)
     {
         var db2         = new KissiContext();
         var currentUser = db2.Customers.Find(customer.CustomerId);
         if (currentUser.UserName != customer.UserName)
         {
             UsersHelper.UpdateUserName(currentUser.UserName, customer.UserName);
         }
         db2.Dispose();
         db.Entry(customer).State = EntityState.Modified;
         var response = DBHelper.SaveChanges(db);
         if (response.Succeeded)
         {
             //UsersHelper.CreateUserASP(customer.UserName, "Customer");
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, response.Message);
         //return RedirectToAction("Index");
     }
     ViewBag.CityId = new SelectList(CombosHelper.GetCities(customer.DepartmentId), "CityId", "Name", customer.CityId);
     //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", customer.CompanyId);
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", customer.DepartmentId);
     return(View(customer));
 }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "StateId,Description")] State state)
 {
     if (ModelState.IsValid)
     {
         db.Entry(state).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(state));
 }
Esempio n. 10
0
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", category.CompanyId);
     return(View(category));
 }
Esempio n. 11
0
 public ActionResult Edit(Tax tax)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tax).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", tax.CompanyId);
     return(View(tax));
 }
Esempio n. 12
0
 public ActionResult Edit(Warehouse warehouse)
 {
     if (ModelState.IsValid)
     {
         db.Entry(warehouse).State = EntityState.Modified;
         var response = DBHelper.SaveChanges(db);
         if (response.Succeeded)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError(string.Empty, response.Message);
     }
     ViewBag.CityId = new SelectList(CombosHelper.GetCities(warehouse.DepartmentId), "CityId", "Name", warehouse.CityId);
     //ViewBag.CompanyId = new SelectList(db.Companies, "CompanyId", "Name", warehouse.CompanyId);
     ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartment(), "DepartmentId", "Name", warehouse.DepartmentId);
     return(View(warehouse));
 }