Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(DoctorCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var  doctorMap = _mapper.Map <Doctor>(viewModel);
            Guid isGuid;

            Guid.TryParse(viewModel.ExpertiseId, out isGuid);
            if (isGuid != Guid.Empty)
            {
                doctorMap.ExpertiseId = Guid.Parse(viewModel.ExpertiseId);
            }
            else
            {
                doctorMap.Expertise = new Expertise
                {
                    ExpertiseName = viewModel.ExpertiseId
                }
            };


            _doctors.Add(doctorMap);
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task BanByIdAsync(Guid userId)
        {
            // Process
            var user = await _users.FirstOrDefaultAsync(model => model.Id == userId);

            user.IsBan = true;
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());

            await UpdateSecurityStampAsync(userId);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(ExpertiseCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var expertiseMap = _mapper.Map <Expertise>(viewModel);

            _expertises.Add(expertiseMap);
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 4
0
        public async Task CreateByViewModelAsync(DocumentSaleCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException();
            }

            var documentSale = _mapper.Map <Sale>(viewModel);

            _documentSales.Add(documentSale);
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(ProductBuyCreateViewModel viewModel)
        {
            // Check
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            // Process
            var productBuyMap = _mapper.Map <ProductBuy>(viewModel);
            var productBuy    = _productBuys.Add(productBuyMap);
            var result        = await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(DocumentCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var document = _mapper.Map <Document>(viewModel);

            _documentRepository.Add(document);

            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(ReportCreateViewModel viewModel)
        {
            var report = _mapper.Map <Report>(viewModel);

            var buffer = new byte[viewModel.ContentFile.InputStream.Length];

            viewModel.ContentFile.InputStream.Read(buffer, 0, buffer.Length);
            report.Content = Encoding.UTF8.GetString(buffer);

            _reportRepository.Add(report);

            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(SmsCreateViewModel viewModel)
        {
            // Check
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            // Process
            var sms = _mapper.Map <Sms>(viewModel);

            _smses.Add(sms);
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 9
0
        /// <summary>
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(AddressCreateViewModel viewModel)
        {
            // Check
            if (viewModel == null)
            {
                throw new ArgumentException(nameof(viewModel));
            }

            // Process
            var address = _mapper.Map <Address>(viewModel);

            _addressStore.Add(address);
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(ProductCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var productMap = _mapper.Map <Product>(viewModel);
            var product    = _products.Add(productMap);

            product.IsActive  = true;
            product.IsProduct = true;
            await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }
Exemplo n.º 11
0
        /// <inheritdoc />
        ///  <summary>
        ///  </summary>
        ///  <param name="viewModel"></param>
        ///  <returns></returns>
        public async Task CreateByViewModelAsync(RoleCreateViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var role = _mapper.Map <Role>(viewModel);

            role.Code = await GenerateCodeAsync();

            var permissionIds = viewModel.Permissions.Split(',');

            role.RolePermissions = new HashSet <RolePermission>();
            permissionIds.ForEach(permissionId => role.RolePermissions.Add(new RolePermission {
                PermissionId = permissionId.ToGuidOrDefault()
            }));
            role.CreatedById = _httpContextManager.CurrentUserId();
            role.CreatedOn   = DateTime.Now;
            _roleRepository.Add(role);

            await _unitOfWork.SaveAllChangesAsync();

            _eventPublisher.EntityInserted(role);
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isCurrentUser"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <Guid?> GetUserIdAsync(bool isCurrentUser, Guid?userId)
        {
            if (isCurrentUser)
            {
                return(_httpContextManager.CurrentUserId());
            }

            return(userId);
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public async Task CreateByViewModelAsync(RoleCreateViewModel viewModel)
        {
            //  Check
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            //  Process
            var role = _mapper.Map <Role>(viewModel);

            var permissions = viewModel.Permissions.Split(',');
            var doc         = new XDocument();

            doc.Add(new XElement("Permissions", permissions.Select(x => new XElement("Permission", x))));
            role.Permissions = doc.ToString();

            var created = _roles.Add(role);
            var result  = await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId());
        }