Пример #1
0
        public Entity.ActionStatus Manage(Entity.AdminRule request)
        {
            try
            {
                Entity.ActionStatus actionStatus = new Entity.ActionStatus(false);
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var checkForExisting = _adminRuleRepository.FindBy(x => x.Name.Equals(request.Name)).Any();

                    if (!checkForExisting)
                    {
                        var dbAdminRule = Mapper.Configuration.Mapper.Map <Entity.AdminRule, Model.AdminRule>(request);
                        dbAdminRule.Guid        = Guid.NewGuid();
                        dbAdminRule.CreatedDate = DateTime.Now;
                        dbAdminRule.CreatedBy   = SolutionConfiguration.CurrentUserId;
                        dbAdminRule.IsActive    = true;
                        actionStatus            = _adminRuleRepository.Insert(dbAdminRule);
                        actionStatus.Data       = Mapper.Configuration.Mapper.Map <Model.AdminRule, Entity.AdminRule>(actionStatus.Data);
                    }
                    else
                    {
                        actionStatus.Message = "Rule Name Already Exist.";
                        actionStatus.Success = false;
                        actionStatus.Data    = request;
                    }
                }
                else
                {
                    var dbAdminRule = _adminRuleRepository.GetByUniqueId(x => x.Guid == request.Guid);
                    if (dbAdminRule == null)
                    {
                        throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : AdminRule");
                    }

                    //request.CreatedBy = dbAdminRule.CreatedBy;
                    //request.CreatedDate = dbAdminRule.CreatedDate;
                    request.IsActive        = dbAdminRule.IsActive;
                    dbAdminRule             = Mapper.Configuration.Mapper.Map <Entity.AdminRule, Model.AdminRule>(request, dbAdminRule);
                    dbAdminRule.UpdatedDate = DateTime.Now;
                    dbAdminRule.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                    actionStatus            = _adminRuleRepository.Update(dbAdminRule);
                    actionStatus.Data       = Mapper.Configuration.Mapper.Map <Model.AdminRule, Entity.AdminRule>(actionStatus.Data);
                }
                return(actionStatus);
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                return(new Entity.ActionStatus
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }
Пример #2
0
 public Entity.BaseResponse <Entity.AdminRule> Manage([FromBody] Entity.AdminRule request)
 {
     Entity.BaseResponse <Entity.AdminRule> response = new Entity.BaseResponse <Entity.AdminRule>(true);
     try
     {
         var status = _service.Manage(request);
         response.IsSuccess = status.Success;
         response.Message   = status.Message;
         response.Data      = status.Data;
     }
     catch (Exception ex)
     {
         base.LogException(ex);
         return(new Entity.BaseResponse <Entity.AdminRule>(false, ex.Message));
     }
     return(response);
 }
Пример #3
0
        public Entity.ActionStatus Manage(Entity.AdminRule request)
        {
            try
            {
                Entity.ActionStatus actionStatus = null;
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var dbAdminRule = Mapper.Configuration.Mapper.Map <Entity.AdminRule, Model.AdminRule>(request);
                    dbAdminRule.Guid        = Guid.NewGuid();
                    dbAdminRule.CreatedDate = DateTime.Now;
                    dbAdminRule.CreatedBy   = SolutionConfiguration.CurrentUserId;
                    dbAdminRule.IsActive    = true;
                    actionStatus            = _adminRuleRepository.Insert(dbAdminRule);
                    actionStatus.Data       = Mapper.Configuration.Mapper.Map <Model.AdminRule, Entity.AdminRule>(actionStatus.Data);
                }
                else
                {
                    var dbAdminRule = _adminRuleRepository.GetByUniqueId(x => x.Guid == request.Guid);
                    if (dbAdminRule == null)
                    {
                        throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : AdminRule");
                    }

                    request.CreatedBy       = dbAdminRule.CreatedBy;
                    request.CreatedDate     = dbAdminRule.CreatedDate;
                    request.IsActive        = dbAdminRule.IsActive;
                    dbAdminRule             = Mapper.Configuration.Mapper.Map <Entity.AdminRule, Model.AdminRule>(request, dbAdminRule);
                    dbAdminRule.UpdatedDate = DateTime.Now;
                    dbAdminRule.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                    actionStatus            = _adminRuleRepository.Update(dbAdminRule);
                    actionStatus.Data       = Mapper.Configuration.Mapper.Map <Model.AdminRule, Entity.AdminRule>(actionStatus.Data);
                }
                return(actionStatus);
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, "AdminRule.Manage " + ex);
                return(new Entity.ActionStatus
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }