コード例 #1
0
        public IActionResult Edit(SpecialPickViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = _dbContext.SpecialPick.FirstOrDefault(x => x.SpecialPickUuid == model.SpecialPickUuid);
                if (entity == null)
                {
                    response.SetFailed("不存在");
                    return(Ok(response));
                }
                if (_dbContext.SpecialPick.Count(x => x.Name == model.Name && x.SpecialPickUuid != model.SpecialPickUuid) > 0)
                {
                    response.SetFailed("名称已存在");
                    return(Ok(response));
                }
                entity.Name         = model.Name;
                entity.Cover        = model.Cover;
                entity.Phone        = model.Phone;
                entity.Introduction = model.Introduction;
                entity.Address      = model.Address;
                entity.Price        = model.Price;
                entity.PlayType     = model.PlayType;
                entity.Picture      = model.Picture;
                entity.State        = model.State;
                entity.Lon          = model.Lon;
                entity.Lat          = model.Lat;
                entity.CreateTime   = Convert.ToDateTime(model.CreateTime);

                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("编辑", "成功:编辑:特色采摘列表数据", _dbContext);
                }
                response = ResponseModelFactory.CreateInstance;
                return(Ok(response));
            }
        }
コード例 #2
0
        public IActionResult Create(SpecialPickViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                if (_dbContext.SpecialPick.Count(x => x.Name == model.Name) > 0)
                {
                    response.SetFailed("名称已存在");
                    return(Ok(response));
                }
                var entity = new SpecialPick();
                //var entity = _mapper.Map<SpecialPickViewModel, SpecialPick>(model);
                entity.Name            = model.Name;
                entity.Cover           = model.Cover;
                entity.Phone           = model.Phone;
                entity.Introduction    = model.Introduction;
                entity.Address         = model.Address;
                entity.Price           = model.Price;
                entity.Picture         = model.Picture;
                entity.PlayType        = model.PlayType;
                entity.State           = model.State;
                entity.Lon             = model.Lon;
                entity.Lat             = model.Lat;
                entity.CreateTime      = Convert.ToDateTime(model.CreateTime);
                entity.SpecialPickUuid = Guid.NewGuid();
                entity.IsDelete        = 0;
                _dbContext.SpecialPick.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:特色采摘列表数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }