public async Task <IActionResult> CreateRetailer([FromForm] CreateUpdateRetailerModel model)
        {
            try
            {
                if (_groupRepository.GetGroup(model.GroupId) != null)
                {
                    var newRetailer = new RetailerModel()
                    {
                        Name             = model.Name,
                        GroupId          = model.GroupId,
                        CreateDate       = DateTime.Now,
                        ModificationDate = DateTime.Now
                    };

                    var newRetailerId = await _retailRepository.AddRetailer(newRetailer);

                    _emitEventLog.EventPublish("created", $"{newRetailerId} at {newRetailer.CreateDate}");

                    return(Ok(newRetailerId));
                }

                return(Error((int)HttpStatusCode.BadRequest));
            }
            catch (Exception ex)
            {
                return(Error((int)HttpStatusCode.BadRequest, ex));
            }
        }
        public IActionResult Add()
        {
            //Prepare a new brand
            var model = new RetailerModel();

            return(PartialView(model));
        }
        public async Task <string> AddRetailer(RetailerModel item)
        {
            await _context.Retails.InsertOneAsync(item);

            var newId = _context.Retails.FindSync(f => f.CreateDate == item.CreateDate).FirstOrDefault();

            return(newId.RetailerId.ToString());
        }
Exemple #4
0
        //public ViewResult Details(int id)
        //{
        //    RetailerModel model = GetModel(id);
        //    return View(model);
        //}
        #endregion

        #region 方法
        private RetailerModel GetModel(int userId)
        {
            RetailerModel model = new RetailerModel();
            Retailer      user  = CurrentDb.Retailer.Where(m => m.Id == userId).FirstOrDefault();

            model.Id          = user.Id;
            model.Name        = user.Name;
            model.BannerImg   = user.BannerImg;
            model.Description = user.Description;
            return(model);
        }
Exemple #5
0
        public void CreatedOn_IsValid()
        {
            // Arrange
            var expected = DateTime.Now;
            var data     = new RetailerModel
            {
                CreatedOn = expected
            };

            // Assert
            Assert.Equal(expected, data.CreatedOn);
        }
Exemple #6
0
        public void Name_IsValid()
        {
            // Arrange
            var expected = "test";
            var data     = new RetailerModel
            {
                Name = expected
            };

            // Assert
            Assert.Equal(expected, data.Name);
        }
Exemple #7
0
        public void RetailerId_IsValid()
        {
            // Arrange
            var expected = 1;
            var data     = new RetailerModel
            {
                RetailerId = expected
            };

            // Assert
            Assert.Equal(expected, data.RetailerId);
        }
        public async Task <IActionResult> Edit(RetailerModel model)
        {
            if (ModelState.IsValid)
            {
                var isSaved = await _retailerManager.SaveRetailer(model);

                if (isSaved)
                {
                    return(RedirectToAction("List"));
                }
            }
            return(View(model)); //TODO: view with validation errors
        }
Exemple #9
0
        public void Products_IsValid()
        {
            // Arrange
            var data = new RetailerModel
            {
                Products = new List <ProductModel>
                {
                    new ProductModel()
                }
            };

            // Assert
            Assert.True(data.Products.Any());
        }
Exemple #10
0
        public JsonResult Update(RetailerModel model)
        {
            Retailer retailer = CurrentDb.Retailer.Where(m => m.Id == model.Id).FirstOrDefault();

            if (retailer != null)
            {
                retailer.BannerImg      = model.BannerImg;
                retailer.Description    = model.Description;
                retailer.Mender         = User.Identity.GetUserId <int>();
                retailer.LastUpdateTime = DateTime.Now;
                CurrentDb.SaveChanges();
            }

            return(Json(ResultType.Success, ManagerOperateTipUtils.UPDATE_SUCCESS));
        }
Exemple #11
0
        /// <summary>
        /// TODO:
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <bool> SaveRetailer(RetailerModel model)
        {
            var entity = model?.MapTo <Retailer>();

            if (model.Id < 1)
            {
                await _retailerRepository.Insert(entity);
            }
            else
            {
                await _retailerRepository.Update(entity);
            }

            return(true);
        }
Exemple #12
0
        //public ViewResult Add()
        //{
        //    UserModel model = new UserModel();
        //    return View();
        //}

        public ViewResult Update(int id)
        {
            RetailerModel model = GetModel(id);

            return(View(model));
        }