Example #1
0
        public async Task <IDataResponse <int> > InsertAsync(NotificationModel model)
        {
            if (model.PersonnelId == null)
            {
                var personnels = await _dalPersonnel.TableNoTracking.Where(x => x.PersonnelType != PersonnelType.Admin).ToListAsync();

                var notify = await _dal.InsertAsync(_mapper.Map <Notification>(model));

                foreach (var item in personnels)
                {
                    await _dalPersonnelNotify.InsertAsync(new PersonnelNotification
                    {
                        NotificationId = notify.Data,
                        PersonnelId    = (int)item.Id
                    });
                }
                return(notify);
            }

            var result = await _dal.InsertAsync(_mapper.Map <Notification>(model));

            if (!result.Success)
            {
                return(new ErrorDataResponse <int>());
            }
            await _dalPersonnelNotify.InsertAsync(new PersonnelNotification
            {
                NotificationId = result.Data,
                PersonnelId    = (int)model.PersonnelId,
            });

            return(result);
        }
        public async Task <IEnumerable <IResponse> > SaveRangeAsync(IEnumerable <RuleModel> models)
        {
            var result = new List <IResponse>();

            foreach (var model in models)
            {
                var entity = await _dal.GetAsync(model.Id);

                if (entity == null)
                {
                    entity = new Rule
                    {
                        ApplicationModule = model.ApplicationModule,
                        RoleId            = model.RoleId,
                        View   = model.View,
                        Insert = model.Insert,
                        Update = model.Update,
                        Delete = model.Delete
                    };
                    result.Add(await _dal.InsertAsync(entity));
                }
                else
                {
                    entity.View   = model.View;
                    entity.Insert = model.Insert;
                    entity.Update = model.Update;
                    entity.Delete = model.Delete;
                    result.Add(await _dal.UpdateAsync(entity));
                }
            }
            return(result);
        }
Example #3
0
        public async Task <IDataResponse <int> > InsertAsync(PersonnelModel model)
        {
            var entity   = _mapper.Map <Personnel>(model);
            var password = Helper.CreatePassword();

            HashingHelper.CreatePasswordHash(password, out var passwordHash, out var passwordSalt);
            entity.PasswordHash            = passwordHash;
            entity.PasswordSalt            = passwordSalt;
            entity.RefreshToken            = Helper.CreateToken();
            entity.RefreshTokenExpiredDate = DateTime.Now.AddDays(-1);
            var result = await _dal.InsertAsync(entity);

            if (!result.Success)
            {
                return(result);
            }

            var emailTemplate = await _emailTemplateService.GetTemplateAndEmailParameterAsync(EmailTemplateType.CreatePersonnelPasswordNotification);

            emailTemplate.Body = emailTemplate.Body
                                 .Replace("[Password]", password)
                                 .Replace("[FullName]", $"{model.FirstName} {model.LastName}");

            var emailResult = await _emailService.SendMailAsync(model.Email, emailTemplate);

            return(!emailResult.Success ? new ErrorDataResponse <int>(result.Data, emailResult.Message) : result);
        }
Example #4
0
        public async Task <IDataResponse <int> > InsertAsync(UserModel model)
        {
            var entity = _mapper.Map <User>(model);

            HashingHelper.CreatePasswordHash(model.Password, out var passwordHash, out var passwordSalt);
            entity.PasswordSalt            = passwordSalt;
            entity.PasswordHash            = passwordHash;
            entity.RefreshToken            = Helper.CreateToken();
            entity.RefreshTokenExpiredDate = DateTime.Now.AddDays(-1);
            return(await _dal.InsertAsync(entity));
        }
        public async Task <IDataResponse <int> > InsertAsync(AssigmentModel model)
        {
            model.CreatedUser = $"{_userService.FirstName} {_userService.LastName}";
            if (model.PersonnelId == 0)
            {
                model.PersonnelId = _userService.PersonnelId;
                return(await _dal.InsertAsync(_mapper.Map <Assigment>(model)));
            }
            var assigment = await _dal.InsertAsync(_mapper.Map <Assigment>(model));

            if (!assigment.Success)
            {
                return(new ErrorDataResponse <int>(assigment.Message));
            }

            var result = await _dalNotify.InsertAsync(new Notification
            {
                Message     = NotificationMessage.Message,
                PersonnelId = model.PersonnelId,
                Title       = NotificationMessage.Title,
                AssigmentId = assigment.Data
            });

            if (!result.Success)
            {
                return(new ErrorDataResponse <int>(result.Message));
            }

            await _dalPersonnelNotify.InsertAsync(new PersonnelNotification
            {
                NotificationId = result.Data,
                PersonnelId    = model.PersonnelId,
            });

            return(assigment);
        }
Example #6
0
        public async Task <IDataResponse <ListMessageModel> > InsertMessageAsync(ListMessageModel model)
        {
            var result = await _dal.InsertAsync(_mapper.Map <Message>(model));

            var resultModel = await _dal.TableNoTracking
                              .Include(x => x.Room)
                              .Include(x => x.Account)
                              .Where(x => x.Id == result.Data)
                              .Select(x => new ListMessageModel
            {
                Id        = x.Id,
                AccountId = x.Account.Id,
                RoomId    = x.Room.Id,
                Text      = x.Text,
                RoomName  = x.Room.Name,
                UserName  = x.Account.UserName,
                CreatedAt = x.CreatedAt
            }).FirstOrDefaultAsync();

            return(new SuccessDataResponse <ListMessageModel>(resultModel));
        }
Example #7
0
        public async Task <IResponse> RegisterAsync(RegisterModel model)
        {
            var account = await AccountExistsAsync(model.Email);

            if (!account.Success)
            {
                return(new ErrorResponse(AccountMessage.AccountExists));
            }

            var entity = _mapper.Map <Account>(model);

            HashingHelper.CreatePasswordHash(model.Password, out var passwordHash, out var passwordSalt);
            entity.PasswordHash            = passwordHash;
            entity.PasswordSalt            = passwordSalt;
            entity.RefreshToken            = Helper.CreateToken();
            entity.RefreshTokenExpiredDate = DateTime.Now.AddDays(-1);
            var result = await _dal.InsertAsync(entity);

            if (!result.Success)
            {
                return(result);
            }
            return(new SuccessResponse(DbMessage.DataInserted));
        }
Example #8
0
 public async Task <IDataResponse <int> > InsertAsync(CategoryModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <Category>(model)));
 }
Example #9
0
 public async Task <IDataResponse <int> > InsertAsync(RoleModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <Role>(model)));
 }
 public async Task <IDataResponse <int> > InsertAsync(DepartmentModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <Department>(model)));
 }
Example #11
0
 public async Task <IDataResponse <int> > InsertAsync(ProductModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <Product>(model)));
 }
 public async Task <IDataResponse <int> > InsertAsync(EmailTemplateModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <EmailTemplate>(model)));
 }
Example #13
0
 public async Task <IDataResponse <int> > InsertAsync(AuthorModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <Author>(model)));
 }
Example #14
0
 public async Task <IDataResponse <int> > InsertAsync(AssigmentTagModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <AssigmentTag>(model)));
 }
 public async Task <IDataResponse <int> > InsertAsync(EmailParameterModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <EmailParameter>(model)));
 }
 public async Task <IDataResponse <int> > InsertAsync(PersonnelNotificationModel model)
 {
     return(await _dal.InsertAsync(_mapper.Map <PersonnelNotification>(model)));
 }