Example #1
0
        public IActionResult Register([FromBody] UserDto userDto)
        {
            // map dto to entity
            var    userReq = _mapper.Map <AcUser>(userDto);
            string newPassword;

            if (userDto.GenPassword)
            {
                newPassword = Functions.RandString(8);
            }
            else
            {
                newPassword = userDto.LoginPassword;
            }
            try
            {
                // check if admin
                AcUser user = new AcUser();
                if (userDto.UsrEmail != null)
                {
                    user = _userService.Create(userReq, newPassword);
                    if (userDto.GenPassword)
                    {
                        _mailService.Send(user.UsrEmail, "Your password is: " + newPassword, "Mobilisis User Account");
                    }
                }
                else
                {
                    List <AcTrigger> trgs = _triggerService.GetByValue(userDto.PhoneNumber);
                    if (trgs.Count > 0)
                    {
                        throw new AppException("Phone number already exists.");
                    }
                    userReq.UsrEmail    = "guest-" + userDto.PhoneNumber;
                    userReq.UsrName     = "guest-" + userDto.PhoneNumber;
                    userReq.UsrActivity = 1;
                    user = _userService.Create(userReq, newPassword);
                    _triggerService.Create(user.UsrId, "Sms", userDto.PhoneNumber, 1);
                    _triggerService.Create(user.UsrId, "Phone", userDto.PhoneNumber, 1);
                    AcAccess acs = _accessService.Create(new AccessDto
                    {
                        ObjId     = userDto.guestObjId,
                        UsrId     = user.UsrId,
                        ValidFrom = userDto.guestValidFrom,
                        ValidTo   = userDto.guestValidTo
                    });
                    _mailService.SendSMS(userDto.PhoneNumber, "You were added access to following object: " + acs.AcsObj.ObjName);
                    // send sms
                }
                return(Ok(user.UsrId));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
 public IActionResult Create([FromBody] TriggerTypeValueDto trgDto)
 {
     try
     {
         // check if admin
         _triggerService.Create(trgDto.trgUsrId, trgDto.trgTrtId, trgDto.trgValue, (byte)trgDto.trgActivity);
         return(Ok());
     }
     catch (AppException ex)
     {
         // return error message if there was an exception
         return(BadRequest(new { message = ex.Message }));
     }
 }