Exemple #1
0
        public async Task <ActionResult> HeThongDeleteGianHangChungConfirmed(int?id)
        {
            GianHangChung _gianhang = await db.GianHangChungs.FindAsync(id);

            if (_gianhang == null)
            {
                return(RedirectToRoute("AdminPanel"));
            }

            try
            {
                if (_gianhang.MatHangChungs.Count > 0)
                {
                    TempData["Updated"] = "Gian hàng này đang có mặt hàng, bạn không thể xóa.";
                    return(RedirectToRoute("HethongDeleteGHC", new { id = _gianhang.GianHangChungId }));
                }

                db.GianHangChungs.Remove(_gianhang);
                await db.SaveChangesAsync();

                TempData["Updated"] = "Xóa gian hàng thành công";
                return(RedirectToRoute("HethongListGHC"));
            }
            catch
            {
                return(RedirectToRoute("AdminPanel"));
            }
        }
Exemple #2
0
        public ActionResult HeThongDeleteGianHangChung(int?id)
        {
            if (id == null || id == 0)
            {
                return(RedirectToRoute("AdminPanel"));
            }
            GianHangChung _gianhang = db.GianHangChungs.Find(id);

            if (_gianhang == null)
            {
                return(RedirectToRoute("AdminPanel"));
            }
            return(View(_gianhang));
        }
Exemple #3
0
        public async Task <ActionResult> HeThongEditGianHangChung(int?id)
        {
            if (id == null || id == 0)
            {
                return(RedirectToRoute("AdminPanel"));
            }
            GianHangChung _gianhang = await db.GianHangChungs.FindAsync(id);

            if (_gianhang == null)
            {
                return(RedirectToRoute("AdminPanel"));
            }
            var getGianHang = new GianHangChungModel()
            {
                GianHangChungId  = _gianhang.GianHangChungId,
                HeThongId        = _gianhang.HeThongId ?? 0,
                AnhGianHang      = _gianhang.AnhGianHang ?? "",
                MaGianHangChung  = _gianhang.MaGianHangChung != null?_gianhang.MaGianHangChung.Split('-')[1] : "",
                TenGianHangChung = _gianhang.TenGianHangChung ?? ""
            };

            return(View(getGianHang));
        }
Exemple #4
0
        public async Task <ActionResult> HethongAddNewGianHangChung(GianHangChungModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Vui lòng kiểm tra lại thông tin gian hàng.";
                return(RedirectToRoute("HethongAddNewGHC"));
            }

            int HeThongId = 0;
            var userLogin = User.Identity.Name != null?db.HeThongs.Where(x => x.Email == User.Identity.Name).FirstOrDefault() : null;

            if (userLogin != null)
            {
                HeThongId = userLogin.HeThongId;
            }
            string _ghcc = string.Format("{0}-{1}", HeThongId, model.MaGianHangChung);
            var    _gh   = db.GianHangChungs.Where(x => x.MaGianHangChung == _ghcc).FirstOrDefault();

            if (_gh != null)
            {
                TempData["Error"] = "Mã gian hàng đã tồn tại.";
                return(RedirectToRoute("HethongAddNewGHC"));
            }

            try
            {
                GianHangChung _newGhc = new GianHangChung();
                _newGhc.MaGianHangChung = model.MaGianHangChung != null?string.Format("{0}-{1}", HeThongId, model.MaGianHangChung) : null;

                _newGhc.TenGianHangChung = model.TenGianHangChung ?? null;
                _newGhc.AnhGianHang      = model.AnhGianHang ?? null;
                _newGhc.HeThongId        = HeThongId != 0 ? HeThongId : (int?)null;
                db.GianHangChungs.Add(_newGhc);
                await db.SaveChangesAsync();

                // save a copy gianhangnew to gianhang cua tat ca sieuthi trong hethong.
                //try
                //{
                //    var sieuthiid = userLogin.SieuThis.Select(x => x.SieuThiId).ToArray();
                //    if (sieuthiid.Length > 0)
                //    {
                //        foreach (var item in sieuthiid)
                //        {
                //            GianHang _ghr = new GianHang();
                //            _ghr.MaGianHang = _newGhc.MaGianHangChung;
                //            _ghr.TenGianHang = _newGhc.TenGianHangChung;
                //            _ghr.AnhGianHang = _newGhc.AnhGianHang;
                //            _ghr.SieuThiId = item;
                //            db.GianHangs.Add(_ghr);
                //            await db.SaveChangesAsync();
                //        }
                //    }


                //}
                //catch (Exception ex)
                //{
                //    Helpers.Config.SaveToLog(ex.ToString());
                //}

                TempData["Updated"] = "Đã thêm mới gian hàng " + model.TenGianHangChung ?? "" + " vào hệ thống";
            }
            catch
            {
                TempData["Error"] = "Có lỗi xảy ra khi thêm gian hàng.";
                return(RedirectToRoute("HethongAddNewGHC"));
            }
            return(RedirectToRoute("HethongListGHC"));
        }