示例#1
0
        public async Task <int> UpdatePhieuNhanHang(PhieuNhanHang phieuNhanHang)
        {
            _context.Entry(phieuNhanHang).State = EntityState.Modified;
            _context.Entry(phieuNhanHang).Property("NgayLap").IsModified = false;

            return(await _context.SaveChangesAsync());
        }
        public async Task <IActionResult> CreateConfirmed(
            [Bind("PhieuNhapHangId")] PhieuNhanHang phieuNhanHang,
            bool?modal, bool?redirect)
        {
            AddInfoToViewData();

            bool isModal    = modal ?? false;
            bool isRedirect = redirect ?? true;

            Message message = new Message();

            if (ModelState.IsValid)
            {
                try
                {
                    phieuNhanHang.NgayLap  = DateTime.Now;
                    phieuNhanHang.NhanVien = await _bookStoreData
                                             .GetStaffByUserName(User.Identity.Name);

                    phieuNhanHang.NhanVienId = phieuNhanHang.NhanVien.Id;

                    await _bookStoreData.AddPhieuNhanHang(phieuNhanHang);

                    message.Type    = MessageType.Success;
                    message.Header  = _sharedLocalizer["Success"];
                    message.Content = string.Format(
                        "{0} {1}",
                        _sharedLocalizer[action],
                        _sharedLocalizer[controller].Value.ToLower());

                    //if (isModal)
                    //    message.Results["Reload"] = true;

                    if (isRedirect)
                    {
                        message.Results["RedirectUrl"] = Url.Action(
                            "Details",
                            new { id = phieuNhanHang.Id });
                    }
                    else
                    {
                        message.Results["Current"] = new
                        {
                            value = phieuNhanHang.Id,
                        }
                    };
                }
                catch (Exception ex)
                {
                    message.Type    = MessageType.Error;
                    message.Header  = _sharedLocalizer["DefaultErrorHeader"];
                    message.Content = _sharedLocalizer[ex.GetType().FullName];
                }
            }

            return(Json(message));
        }
        private async Task <IActionResult> RUD(int?id, bool?modal, bool?redirect)
        {
            AddInfoToViewData();

            bool isModal    = modal ?? false;
            bool isRedirect = redirect ?? true;

            Message message = new Message();

            if (id == null)
            {
                if (isModal)
                {
                    message.Type    = MessageType.Error;
                    message.Header  = _sharedLocalizer["DefaultErrorHeader"];
                    message.Content = _sharedLocalizer["NotFound"];
                }
            }

            try
            {
                PhieuNhanHang phieuNhanHang =
                    await _bookStoreData.GetPhieuNhanHangById(id);

                if (phieuNhanHang == null)
                {
                    if (isModal)
                    {
                        message.Type    = MessageType.Error;
                        message.Header  = _sharedLocalizer["DefaultErrorHeader"];
                        message.Content = _sharedLocalizer["NotFound"];
                    }
                }
                else
                {
                    ViewData["Modal"]    = isModal;
                    ViewData["Redirect"] = isRedirect;

                    if (isModal)
                    {
                        return(PartialView(GetUrlPartialPartial(), phieuNhanHang));
                    }
                    else
                    {
                        return(View(phieuNhanHang));
                    }
                }
            }
            catch (Exception ex)
            {
                message.Type    = MessageType.Error;
                message.Header  = _sharedLocalizer["DefaultErrorHeader"];
                message.Content = _sharedLocalizer[ex.GetType().FullName];
            }

            if (isModal)
            {
                return(Json(message));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
示例#4
0
        public async Task <int> AddPhieuNhanHang(PhieuNhanHang phieuNhanHang)
        {
            await _context.PhieuNhanHang.AddAsync(phieuNhanHang);

            return(await RecivePhieuNhapHang(phieuNhanHang.PhieuNhapHangId));
        }