Пример #1
0
        public async Task <Response> AddGood(GoodsTypeVM goods)
        {
            var goodsDto = Mapper.Map <GoodsTypeVM, GoodsType>(goods);

            GoodsType goodsExist = await _db.GoodsTypes.Where(x => x.Goods.Trim() == goods.Goods.Trim()).FirstOrDefaultAsync();

            if (goodsExist != null)
            {
                return(GenericResponses <int> .ResponseStatus(true, Constant.MDGNoAlreadyExist, (int)Constant.httpStatus.NoContent, 0));
            }

            _db.GoodsTypes.Add(goodsDto);

            int result = await _db.SaveChangesAsync();

            if (result == 1)
            {
                // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>());

                return(GenericResponses <int> .ResponseStatus(false, Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, result));
            }
            else
            {
                return(GenericResponses <int> .ResponseStatus(true, Constant.MDGNoLoginFailed, (int)Constant.httpStatus.NoContent, result));
            }
        }
Пример #2
0
        public async Task <Response> RemoveGood(GoodsTypeVM goods)
        {
            try
            {
                var goodsDTO = await _db.GoodsTypes.Where(x => x.Id == goods.Id).FirstOrDefaultAsync();

                _db.GoodsTypes.Remove(goodsDTO);

                int result = await _db.SaveChangesAsync();

                if (result == 1)
                {
                    // Mapper.Initialize(cfg => cfg.CreateMap<User, UserVM>());

                    return(GenericResponses <int> .ResponseStatus(false, Constant.MSGRecordFound, (int)Constant.httpStatus.Ok, result));
                }
                else
                {
                    return(GenericResponses <int> .ResponseStatus(true, Constant.MSGFailed, (int)Constant.httpStatus.NoContent, result));
                }
            }
            catch (Exception e)
            {
                return(GenericResponses <int> .ResponseStatus(true, e.Message, (int)Constant.httpStatus.NoContent, 0));
            }
        }
Пример #3
0
        public async Task <JsonResult> RemoveGoods(GoodsTypeVM good)
        {
            Response r = await goodsRepository.RemoveGood(good);

            //  List<UserVM> employees = ((IEnumerable)r.Value).Cast<UserVM>().ToList(); ;
            return(Json(r, JsonRequestBehavior.AllowGet));
        }