コード例 #1
0
        public async Task <IActionResult> Create(MN_CustomerGroup model, bool SaveAndCountinue = false)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var obj = new MN_CustomerGroup()
            {
                Description = model.Description,
                Id          = ObjectId.GenerateNewId().ToString(),
                Name        = model.Name,
                Ordering    = model.Ordering,
            };

            //Thực hiện thêm mới
            var result = await _MN_CustomerGroupService.Create(obj);

            if (result.isSuccess)
            {
                if (SaveAndCountinue)
                {
                    TempData["Success"] = "Thêm mới thành công";
                    return(RedirectToAction("Create"));
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Update(MN_CustomerGroup model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var oldObj = await _MN_CustomerGroupService.GetById(model.Id);

            if (oldObj == null)
            {
                ModelState.AddModelError("", "Bản ghi không tồn tại");
                return(View(model));
            }

            oldObj.Description = model.Description;
            oldObj.Name        = model.Name;
            oldObj.Ordering    = model.Ordering;

            var result = await _MN_CustomerGroupService.Update(oldObj);

            if (result.isSuccess)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(model));
            }
        }
コード例 #3
0
        public async Task <MessageReport> Update(MN_CustomerGroup model)
        {
            var query = new StringBuilder();

            query.AppendLine("{");
            query.AppendLine("'_id': { '$eq': '" + model.Id + "' }");
            query.AppendLine("}");

            return(await _MN_CustomerGroupRepository.Update(MongoHelper.ConvertQueryStringToDocument(query.ToString()), model));
        }
コード例 #4
0
 public async Task <MessageReport> Create(MN_CustomerGroup model)
 {
     return(await _MN_CustomerGroupRepository.Add(model));
 }
コード例 #5
0
        public async Task <IActionResult> Create(MN_CustomerGroup model)
        {
            model = model == null ? new MN_CustomerGroup() : model;

            return(View(await Task.FromResult(model)));
        }