Esempio n. 1
0
        public async Task <bool> Add(LcdaModel lcdaModel)
        {
            Lcda lcda = _mapper.Map <Lcda>(lcdaModel);

            _context.Lcdas.Add(lcda);
            int count = await _context.SaveChangesAsync();

            return(count > 0);
        }
Esempio n. 2
0
        public async Task <LcdaModel> Get(string lcdaCode)
        {
            var r = await _context.Lcdas.FirstOrDefaultAsync(x => x.LcdaCode == lcdaCode);

            if (r == null)
            {
                return(null);
            }

            LcdaModel lcdaModel = _mapper.Map <LcdaModel>(r);

            return(lcdaModel);
        }
Esempio n. 3
0
        public async Task <LcdaModel> Get(long id)
        {
            var r = await _context.Lcdas.FindAsync(id);

            if (r == null)
            {
                return(null);
            }

            LcdaModel lcdaModel = _mapper.Map <LcdaModel>(r);

            return(lcdaModel);
        }
Esempio n. 4
0
        public async Task <IActionResult> AssignLcdaToUser([FromBody] UserLcdaModel userLcdaModel)
        {
            UserModel userModel = await _userService.Get(userLcdaModel.UserId);

            if (userModel == null)
            {
                throw new BadRequestException("User does not exist");
            }
            if (userModel.userStatus != UserStatus.ACTIVE)
            {
                throw new BadRequestException("User is not active");
            }
            LcdaModel lcdaModel = await _lcdaService.Get(userLcdaModel.LcdaId);

            if (lcdaModel == null)
            {
                throw new BadRequestException("Lcda does not exist");
            }
            if (lcdaModel.LcdaStatus != LcdaStatus.ACTIVE)
            {
                throw new BadRequestException("LCDA is not active");
            }

            UserLcdaModel ulModel = await _userLcdaService.Get(userLcdaModel);

            if (ulModel != null)
            {
                throw new BadRequestException("User already have access to the lcda");
            }

            bool result = await _userLcdaService.Add(userLcdaModel);

            if (result)
            {
                return(Ok(new ResponseModel()
                {
                    code = ResponseCode.SUCCESSFULL,
                    description = "User has been added to the LCDA successfully"
                }));
            }

            throw new UnknownException("An error occured while trying to assign user to lcda");
        }
Esempio n. 5
0
        public async Task <bool> Update(LcdaModel lcdaModel)
        {
            var r = await _context.Lcdas.FindAsync(lcdaModel.Id);

            if (r == null)
            {
                return(false);
            }
            //r.LcdaCode = lcdaModel.LcdaCode;
            r.LcdaName = lcdaModel.LcdaName;

            int count = await _context.SaveChangesAsync();

            if (count > 0)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        public async Task <IActionResult> Add([FromBody] LcdaModel lcdaModel)
        {
            long lastId = await _lcdaService.LastId();

            lcdaModel.LcdaCode = _codeGenerationService.NewLcdaCode(lastId);
            bool result = await _lcdaService.Add(lcdaModel);

            if (result)
            {
                // add current user to the lcda
                LcdaModel lModel = await _lcdaService.Get(lcdaModel.LcdaCode);

                return(Ok(new ResponseModel()
                {
                    code = ResponseCode.SUCCESSFULL,
                    data = lModel.Id,
                    description = $"{lcdaModel.LcdaName} has been created successfully"
                }));
            }

            throw new BadRequestException("An error occur while processing your request. Please try again or contact an administrator");
        }
Esempio n. 7
0
 public Task <bool> Update(LcdaModel lcdaModel)
 {
     return(_lcdaManager.Update(lcdaModel));
 }
Esempio n. 8
0
 public Task <bool> Add(LcdaModel lcdaModel)
 {
     return(_lcdaManager.Add(lcdaModel));
 }