public async Task <IActionResult> SupplierSave(SupplierModel sm)
        {
            ServiceReference_Supplier.Supplier s = new ServiceReference_Supplier.Supplier();
            s.SupplierId      = sm.SupplierId;
            s.CompanyName     = sm.CompanyName;
            s.Email           = sm.Email;
            s.Phone           = sm.Phone;
            s.Address         = sm.Address;
            s.Province        = sm.Province;
            s.MainProduct     = sm.MainProduct;
            s.CategoryId      = sm.CategoryId;
            s.Website         = sm.Website;
            s.Zipcode         = sm.Zipcode;
            s.CountryId       = sm.CountryId;
            s.Status          = sm.Status;
            s.BussinessType   = sm.BussinessType;
            s.YearEstablished = sm.YearEstablished;
            s.TotalEmployees  = sm.TotalEmployees;
            bool _boolean = await sup.createSupplierAsync(s);

            if (_boolean)
            {
                flag    = "success";
                message = "Add new supplier success.";
                return(RedirectToAction("SupplierCreate"));
            }
            else
            {
                flag    = "error";
                message = "Add new supplier fail.";
                return(RedirectToAction("SupplierCreate"));
            }
        }
Example #2
0
        // Edit profile

        public async Task <IActionResult> SupplierEdit()
        {
            try
            {
                ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

                _id = await getSupplierIdByEmail(user.Email);

                ServiceReference_Supplier.Supplier su = await s.findSupplierByIdAsync(_id);

                ServiceReference_Category.Category[] lst_categories = await cc.getAllCategoryAsync();

                ServiceReference_Country.Country[] lst_countries = await co.getAllCountryAsync();

                SupplierModel sm = new SupplierModel()
                {
                    categories      = lst_categories,
                    countries       = lst_countries,
                    SupplierId      = su.SupplierId,
                    Avatar          = su.Avatar,
                    Name            = su.Name,
                    Title           = su.Title,
                    CompanyName     = su.CompanyName,
                    Email           = su.Email,
                    Phone           = su.Phone,
                    Address         = su.Address,
                    Province        = su.Province,
                    MainProduct     = su.MainProduct,
                    CategoryId      = (int)su.CategoryId,
                    Website         = su.Website,
                    Zipcode         = su.Zipcode,
                    CountryId       = (int)su.CountryId,
                    Status          = su.Status,
                    BussinessType   = su.BussinessType,
                    YearEstablished = su.YearEstablished,
                    TotalEmployees  = su.TotalEmployees
                };
                ViewBag.flag    = flag;
                ViewBag.message = message;
                flag            = "";
                message         = "";
                return(View(sm));
            }
            catch (Exception)
            {
                return(RedirectToAction("SupplierEdit"));
            }
        }
Example #3
0
        public async Task <string> upload()
        {
            ServiceReference_Supplier.Supplier supplier = await s.findSupplierByIdAsync(_id);

            string path     = _host.WebRootPath + @"\images\";
            string filename = "";

            // Checking no of files injected in Request object
            if (Request.Form.Files.Count > 0)
            {
                try
                {
                    foreach (IFormFile f in Request.Form.Files)
                    {
                        filename = f.FileName;
                        if (System.IO.File.Exists(path + filename))
                        {
                            System.IO.File.Delete(path + filename);
                        }
                        System.IO.FileStream fs = System.IO.File.Create(path + filename);

                        f.CopyTo(fs);
                        fs.Flush();
                        fs.Dispose();
                    }
                    // Returns message that successfully uploaded
                    supplier.Avatar = filename;
                    bool res = await s.updateSupplierAsync(supplier);

                    return(filename);
                }
                catch (Exception ex)
                {
                    return("error");
                }
            }
            else
            {
                return("No files selected.");
            }
        }
Example #4
0
        public async Task <IActionResult> SupplierUpdate(SupplierModel sm)
        {
            ServiceReference_Supplier.Supplier su = await s.findSupplierByIdAsync(sm.SupplierId);

            su.SupplierId = sm.SupplierId;
            //su.Avatar = sm.Avatar;
            su.Name            = sm.Name;
            su.Title           = sm.Title;
            su.CompanyName     = sm.CompanyName;
            su.Email           = sm.Email;
            su.Phone           = sm.Phone;
            su.Address         = sm.Address;
            su.Province        = sm.Province;
            su.MainProduct     = sm.MainProduct;
            su.CategoryId      = sm.CategoryId;
            su.Website         = sm.Website;
            su.Zipcode         = sm.Zipcode;
            su.Country         = sm.Country;
            su.CountryId       = sm.CountryId;
            su.Status          = sm.Status;
            su.BussinessType   = sm.BussinessType;
            su.YearEstablished = sm.YearEstablished;
            su.TotalEmployees  = sm.TotalEmployees;
            bool _boolean = await s.updateSupplierAsync(su);

            if (_boolean)
            {
                flag    = "success";
                message = "Update profile success.";
                return(RedirectToAction("SupplierEdit"));
            }
            else
            {
                flag    = "success";
                message = "Update profile success.";
                return(RedirectToAction("SupplierEdit"));
            }
        }
        public async Task <IActionResult> SupplierEdit(string id)
        {
            ServiceReference_Supplier.Supplier s = await sup.findSupplierByIdAsync(id);

            ServiceReference_Category.Category[] lst_categories = await cs.getAllCategoryAsync();

            ServiceReference_Country.Country[] lst_countries = await co.getAllCountryAsync();

            SupplierModel sm = new SupplierModel()
            {
                categories      = lst_categories,
                countries       = lst_countries,
                SupplierId      = s.SupplierId,
                Avatar          = s.Avatar,
                CompanyName     = s.CompanyName,
                Email           = s.Email,
                Phone           = s.Phone,
                Address         = s.Address,
                Province        = s.Province,
                MainProduct     = s.MainProduct,
                CategoryId      = (int)s.CategoryId,
                Website         = s.Website,
                Zipcode         = s.Zipcode,
                CountryId       = (int)s.CountryId,
                Status          = s.Status,
                BussinessType   = s.BussinessType,
                YearEstablished = s.YearEstablished,
                TotalEmployees  = s.TotalEmployees
            };

            ViewBag.flag    = flag;
            ViewBag.message = message;
            flag            = "";
            message         = "";
            return(View(sm));
        }