public Entity.BaseResponse <Entity.UserDasboardWidget> ManageUserWidget(Entity.UserDasboardWidget request)
 {
     Entity.BaseResponse <Entity.UserDasboardWidget> response = new Entity.BaseResponse <Entity.UserDasboardWidget>(true);
     try
     {
         var result = _service.ManageUserWidget(request);
         response.IsSuccess = result.Success;
         response.Message   = result.Message;
         response.Data      = result.Data;
     }
     catch (Exception ex)
     {
         base.LogException(ex);
         return(new Entity.BaseResponse <Entity.UserDasboardWidget>(false, ex.Message));
     }
     return(response);
 }
コード例 #2
0
        public Entity.ActionStatus ManageUserWidget(Entity.UserDasboardWidget request)
        {
            try
            {
                if (request.DashboardName.ToLower().Trim().Equals("system default"))
                {
                    return(new Entity.ActionStatus
                    {
                        Success = false,
                        Message = "Dashboard Name Can not be System Default !",
                        Data = null
                    });
                }
                Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
                var dbUserWidget = Mapper.Configuration.Mapper.Map <Entity.UserDasboardWidget, Model.UserDasboardWidget>(request);
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var checkExisting = _userDashboardWidgetRepository.FindBy(x => x.DashboardName.Equals(request.DashboardName) && x.UserId == component.helper.SolutionConfiguration.CurrentUserId && x.IsActive == true && !x.IsDeleted).FirstOrDefault();
                    if (checkExisting == null)
                    {
                        if (request.IsDefault)
                        {
                            var response = _userDashboardWidgetRepository.FindBy(r => r.IsDefault == true && r.UserId == component.helper.SolutionConfiguration.CurrentUserId).Select(p => Mapper.Configuration.Mapper.Map <Model.UserDasboardWidget>(p)).FirstOrDefault();
                            if (response != null)
                            {
                                response.IsDefault = false;
                                _userDashboardWidgetRepository.Update(response);
                            }
                        }
                        string renderedValues = string.Join(",", request.WidgetsList);
                        dbUserWidget.Guid   = Guid.NewGuid();
                        dbUserWidget.UserId = component.helper.SolutionConfiguration.CurrentUserId;
                        string res = RemoveWhiteSpace(Convert.ToString(renderedValues));
                        dbUserWidget.Widgets     = "[" + res + "]";
                        dbUserWidget.IsActive    = true;
                        dbUserWidget.IsDeleted   = false;
                        dbUserWidget.CreatedDate = DateTime.Now;
                        dbUserWidget.CreatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                        actionStatus             = _userDashboardWidgetRepository.Insert(dbUserWidget);
                        actionStatus.Data        = Mapper.Configuration.Mapper.Map <Model.UserDasboardWidget, Entity.UserDasboardWidget>(actionStatus.Data);
                    }
                    else
                    {
                        actionStatus.Success = false;
                        actionStatus.Message = "Dashboard Name Already Exists !!";
                    }
                }
                else
                {
                    var uniqUserWidget = _userDashboardWidgetRepository.GetByUniqueId(x => x.Guid == dbUserWidget.Guid);
                    if (uniqUserWidget == null)
                    {
                        throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : User Widget");
                    }
                    if (!uniqUserWidget.DashboardName.Equals(request.DashboardName.Trim()))
                    {
                        var checkExisting = _userDashboardWidgetRepository.FindBy(x => x.DashboardName.Equals(request.DashboardName) && x.UserId == component.helper.SolutionConfiguration.CurrentUserId && x.IsActive == true && !x.IsDeleted).FirstOrDefault();
                        if (checkExisting != null)
                        {
                            return(new Entity.ActionStatus
                            {
                                Success = false,
                                Message = "Widget already exists!",
                                Data = null
                            });
                        }
                    }

                    if (request.IsDefault && !uniqUserWidget.IsDefault)
                    {
                        var response = _userDashboardWidgetRepository.FindBy(r => r.IsDefault == true && r.Guid != request.Guid && r.UserId == component.helper.SolutionConfiguration.CurrentUserId).Select(p => Mapper.Configuration.Mapper.Map <Model.UserDasboardWidget>(p)).FirstOrDefault();
                        if (response != null)
                        {
                            response.IsDefault = false;
                            _userDashboardWidgetRepository.Update(response);
                        }
                    }

                    if (uniqUserWidget != null)
                    {
                        string renderedValues = string.Join(",", request.WidgetsList);
                        string res            = RemoveWhiteSpace(Convert.ToString(renderedValues));
                        uniqUserWidget.DashboardName = request.DashboardName;
                        uniqUserWidget.Widgets       = "[" + res + "]";
                        uniqUserWidget.IsActive      = request.IsActive;
                        uniqUserWidget.IsDefault     = request.IsDefault;
                        uniqUserWidget.ModifiedDate  = DateTime.Now;
                        uniqUserWidget.ModifiedBy    = component.helper.SolutionConfiguration.CurrentUserId;
                        actionStatus      = _userDashboardWidgetRepository.Update(uniqUserWidget);
                        actionStatus.Data = Mapper.Configuration.Mapper.Map <Model.UserDasboardWidget, Entity.UserDasboardWidget>(actionStatus.Data);
                    }
                    else
                    {
                        return(new Entity.ActionStatus
                        {
                            Success = false,
                            Message = "Widget already exists!",
                            Data = null
                        });
                    }
                }
                return(actionStatus);
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                return(new Entity.ActionStatus
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }