public async Task <TResponse <UpdateCrmPriorityModel> > GetById(int userId,
                                                                        int id,
                                                                        int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var crmPriority = await _crmPriorityCacheService.GetById(id);

                    if (crmPriority != null)
                    {
                        return(await Ok(new UpdateCrmPriorityModel(crmPriority)));
                    }

                    return(await Fail <UpdateCrmPriorityModel>(ErrorEnum.CRM_PRIORITY_HAS_NOT_EXIST.GetStringValue()));
                }

                return(await Fail <UpdateCrmPriorityModel>(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <UpdateCrmPriorityModel>(exception));
            }
        }
Example #2
0
        private async Task <string> BuildMessageForUpdate(AuditTableKafkaMessage <AuditCrm> crm)
        {
            StringBuilder builder = new StringBuilder();

            #region Need

            if (string.IsNullOrEmpty(crm.OldValue.Need) &&
                !string.IsNullOrEmpty(crm.Value.Need))
            {
                builder.Append($"Đã thêm mới nhu cầu: <b>{crm.Value.Need}</b>. <br/>");
            }
            else if (!string.IsNullOrEmpty(crm.OldValue.Need) &&
                     string.IsNullOrEmpty(crm.Value.Need))
            {
                builder.Append($"Đã xóa bỏ nhu cầu: <b>{crm.OldValue.Need}</b>. <br/>");
            }
            else if (!string.Equals(crm.OldValue.Need, crm.Value.Need, StringComparison.CurrentCultureIgnoreCase))
            {
                builder.Append($"Đã cập nhật nhu cầu từ <b>{crm.OldValue.Need}</b> sang <b>{crm.Value.Need}</b>. <br/>");
            }

            #endregion

            #region Description

            if (string.IsNullOrEmpty(crm.OldValue.Description) &&
                !string.IsNullOrEmpty(crm.Value.Description))
            {
                builder.Append($"Đã thêm mới ghi chú: <b>{crm.Value.Description}</b>. <br/>");
            }
            else if (!string.IsNullOrEmpty(crm.OldValue.Description) &&
                     string.IsNullOrEmpty(crm.Value.Description))
            {
                builder.Append($"Đã xóa bỏ ghi chú: <b>{crm.OldValue.Description}</b>. <br/>");
            }
            else if (!string.Equals(crm.OldValue.Description, crm.Value.Description, StringComparison.CurrentCultureIgnoreCase))
            {
                builder.Append($"Đã cập nhật ghi chú từ <b>{crm.OldValue.Description}</b> sang <b>{crm.Value.Description}</b>. <br/>");
            }

            #endregion

            #region ContactDate

            if (crm.OldValue.ContactDate != crm.Value.ContactDate)
            {
                builder.Append($"Đã thay đổi ngày liên hệ từ <b>{crm.OldValue.ContactDate:dd-MM-yyyy hh:mm}</b> sang <b>{crm.Value.ContactDate: dd-MM-yyyy hh:mm}</b>. <br/>");
            }

            #endregion

            #region CrmPriorityId

            if (crm.OldValue.CrmPriorityId != crm.Value.CrmPriorityId)
            {
                var oldCrmPriority = await _crmPriorityCacheService.GetById(crm.OldValue.CrmPriorityId);

                var crmPriority = await _crmPriorityCacheService.GetById(crm.Value.CrmPriorityId);

                if (oldCrmPriority != null &&
                    crmPriority != null)
                {
                    builder.Append($"Đã thay đổi mức độ khẩn cấp từ <b>{oldCrmPriority.Name}</b> sang <b>{crmPriority.Name}</b>. <br/>");
                }
            }

            #endregion

            #region CustomerSourceId

            if (crm.OldValue.CustomerSourceId != crm.Value.CustomerSourceId)
            {
                var oldCustomerSource = await _customerSourceCacheService.GetById(crm.OldValue.CustomerSourceId);

                var customerSource = await _customerSourceCacheService.GetById(crm.Value.CustomerSourceId);

                if (oldCustomerSource != null &&
                    customerSource != null)
                {
                    builder.Append($"Đã thay đổi nguồn khách hàng từ <b>{oldCustomerSource.Name}</b> sang <b>{customerSource.Name}</b>. <br/>");
                }
            }

            #endregion

            #region CrmTypeId

            if (crm.OldValue.CrmTypeId != crm.Value.CrmTypeId)
            {
                var oldCrmType = await _crmTypeCacheService.GetById(crm.OldValue.CrmTypeId);

                var crmType = await _crmTypeCacheService.GetById(crm.Value.CrmTypeId);

                if (oldCrmType != null &&
                    crmType != null)
                {
                    builder.Append($"Đã thay đổi kiểu chốt từ <b>{oldCrmType.Name}</b> sang <b>{crmType.Name}</b>. <br/>");
                }
            }

            #endregion

            #region ProductGroupId

            if (crm.OldValue.ProductGroupId != crm.Value.ProductGroupId)
            {
                var oldProductGroup = await _productGroupCacheService.GetById(crm.OldValue.ProductGroupId);

                var productGroup = await _productGroupCacheService.GetById(crm.Value.ProductGroupId);

                if (oldProductGroup != null &&
                    productGroup != null)
                {
                    builder.Append($"Đã thay đổi nhóm sản phẩm từ <b>{oldProductGroup.Name}</b> sang <b>{productGroup.Name}</b>. <br/>");
                }
            }

            #endregion

            #region Visit

            if (crm.OldValue.Visit != crm.Value.Visit)
            {
                if (crm.OldValue.Visit == 0)
                {
                    builder.Append("Đã thay đổi đến cửa hàng từ <b>Chưa đến</b> sang <b>Đã đến</b>. <br/>");
                }
                else
                {
                    builder.Append("Đã thay đổi đến cửa hàng từ <b>Đã đến</b> sang <b>Chưa đến</b>. <br/>");
                }
            }

            #endregion

            #region UserIds

            var addUserIds = crm.Value.UserIds.Where(c => !crm.OldValue.UserIds.Contains(c))
                             .ToList();
            var removeUserIds = crm.OldValue.UserIds.Where(c => !crm.Value.UserIds.Contains(c))
                                .ToList();
            if (addUserIds.Any())
            {
                foreach (var addUserId in addUserIds)
                {
                    var addUser = await _userCacheService.GetById(addUserId);

                    if (addUser != null)
                    {
                        builder.Append($"Đã thêm <b>{addUser.DisplayName}</b> làm người phụ trách. <br/>");
                    }
                }
            }

            if (removeUserIds.Any())
            {
                foreach (var removeUserId in removeUserIds)
                {
                    var removeUser = await _userCacheService.GetById(removeUserId);

                    if (removeUser != null)
                    {
                        builder.Append($"Đã xóa <b>{removeUser.DisplayName}</b> khỏi danh sách người phụ trách. <br/>");
                    }
                }
            }

            #endregion

            return(builder.ToString());
        }