Exemple #1
0
        public Entity.ActionStatus Login(Entity.LoginRequest request)
        {
            Entity.ActionStatus result = new Entity.ActionStatus(true);
            try
            {
                IOT.DataResponse <IOT.LoginResult> loginResult = _iotConnectClient.Login.Login(new IOT.LoginModel()
                {
                    UserName = request.Username,
                    Password = request.Password
                }).Result;

                result.Success = loginResult.status;
                if (loginResult != null && loginResult.status)
                {
                    JwtSecurityTokenHandler hand = new JwtSecurityTokenHandler();
                    var tokenS    = hand.ReadJwtToken(loginResult.data.access_token);
                    var jsonValue = tokenS.Claims?.SingleOrDefault(p => p.Type == "user")?.Value;
                    Entity.UserDetail userDetail = Newtonsoft.Json.JsonConvert.DeserializeObject <Entity.UserDetail>(jsonValue);
                    var user = _userRepository.GetByUniqueId(r => r.Guid == Guid.Parse(userDetail.Id));
                    if (user == null)
                    {
                        return(new Entity.ActionStatus()
                        {
                            Success = false, Message = "User is not exits in solutions"
                        });
                    }
                    userDetail.FullName = user.FirstName.ToString() + " " + user.LastName.ToString();
                    result.Data         = new Entity.LoginResponse
                    {
                        status        = loginResult.data.status,
                        data          = loginResult.data.data,
                        message       = loginResult.message,
                        token_type    = loginResult.data.token_type,
                        access_token  = loginResult.data.access_token,
                        refresh_token = loginResult.data.refresh_token,
                        expires_in    = loginResult.data.expires_in,
                        UserDetail    = userDetail
                    };
                }
                else
                {
                    result.Message = loginResult.message;
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                return(new Entity.ActionStatus(false, ex.Message));
            }
            return(result);
        }
Exemple #2
0
 public Entity.ActionStatus Delete(Guid id)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbEntity = _entityRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbEntity == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Facility");
         }
         var dbChildEntity = _entityRepository.FindBy(x => x.ParentEntityGuid.Equals(id) && !x.IsDeleted).FirstOrDefault();
         var dbDevice      = _deviceRepository.FindBy(x => x.EntityGuid.Equals(id) || (dbChildEntity != null && x.EntityGuid.Equals(dbChildEntity.Guid))).FirstOrDefault();
         if (dbDevice == null && dbChildEntity == null)
         {
             var deleteEntityResult = _iotConnectClient.Entity.Delete(id.ToString()).Result;
             if (deleteEntityResult != null && deleteEntityResult.status)
             {
                 dbEntity.IsDeleted   = true;
                 dbEntity.UpdatedDate = DateTime.Now;
                 dbEntity.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                 return(_entityRepository.Update(dbEntity));
             }
             else
             {
                 _logger.ErrorLog(new Exception($"Facility is not deleted from iotconnect, Error: {deleteEntityResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                 actionStatus.Success = false;
                 actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteEntityResult.errorMessages);
             }
         }
         else if (dbChildEntity != null)
         {
             _logger.ErrorLog(new Exception($"Facility is not deleted in solution database.Zone exists, Error: {actionStatus.Message}"));
             actionStatus.Success = false;
             actionStatus.Message = "Facility is not deleted in solution database.Zone exists";
         }
         else
         {
             _logger.ErrorLog(new Exception($"Facility is not deleted in solution database.Sensor exists, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             actionStatus.Success = false;
             actionStatus.Message = "Facility cannot be deleted because sensor exists";
         }
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
        public Entity.ActionStatus Delete(Guid id)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            try
            {
                var dbRole = _roleRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
                if (dbRole == null)
                {
                    throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Role");
                }
                var userRole = _userRepository.FindBy(x => x.RoleGuid.Equals(id) && x.IsDeleted.Equals(false)).FirstOrDefault();
                if (userRole == null)
                {
                    var deleteRoleResult = _iotConnectClient.Role.DeleteRole(id.ToString()).Result;
                    if (deleteRoleResult != null && deleteRoleResult.status)
                    {
                        dbRole.IsDeleted   = true;
                        dbRole.UpdatedDate = DateTime.Now;
                        dbRole.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                        actionStatus       = _roleRepository.Update(dbRole);
                    }
                    else
                    {
                        _logger.ErrorLog(new Exception($"Role is not deleted in iotconnect, Error: {deleteRoleResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteRoleResult.errorMessages);
                    }
                }
                else
                {
                    _logger.ErrorLog(new Exception($"Role is not deleted in solution database.User exists, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                    actionStatus.Success = false;
                    actionStatus.Message = "Role is not deleted in solution database.User exists";
                }

                //if (!actionStatus.Success)
                //{
                //    _logger.Error($"Role is not deleted in solution database, Error: {actionStatus.Message}");
                //    actionStatus.Success = false;
                //    actionStatus.Message = "Something Went Wrong!";
                //}
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
        public Entity.ActionStatus UpdateStatus(Guid id, bool status)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            try
            {
                var dbEntity = _entityRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
                if (dbEntity == null)
                {
                    throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Entity");
                }

                var dbChildEntity = _entityRepository.FindBy(x => x.ParentEntityGuid.Equals(id) && !x.IsDeleted).FirstOrDefault();
                var dbDevice      = _deviceRepository.FindBy(x => x.EntityGuid.Equals(id) || (dbChildEntity != null && x.EntityGuid.Equals(dbChildEntity.Guid))).FirstOrDefault();
                var dbDeviceType  = _deviceTypeRepository.FindBy(x => x.EntityGuid.Equals(id) && !x.IsDeleted).FirstOrDefault();
                if (dbDevice == null && dbChildEntity == null && dbDeviceType == null)
                {
                    dbEntity.IsActive    = status;
                    dbEntity.UpdatedDate = DateTime.Now;
                    dbEntity.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                    return(_entityRepository.Update(dbEntity));
                }
                else if (dbChildEntity != null)
                {
                    _logger.Error($"Location is not updated in solution database.Zone exists, Error: {actionStatus.Message}");
                    actionStatus.Success = false;
                    actionStatus.Message = "Zone is already associated with Location so its status can not be updated";
                }
                else if (dbDeviceType != null)
                {
                    _logger.Error($"Location is not updated in solution database.Device Type exists, Error: {actionStatus.Message}");
                    actionStatus.Success = false;
                    actionStatus.Message = "Device Type is already associated with Location so its status can not be updated";
                }
                else
                {
                    _logger.Error($"Location is not updated in solution database.Asset exists, Error: {actionStatus.Message}");
                    actionStatus.Success = false;
                    actionStatus.Message = "Location status cannot be updated because asset exists";
                }
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "EntityService.UpdateStatus " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
Exemple #5
0
        public Entity.ActionStatus Manage(Entity.NotificationAddRequest request)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            var _list = new List <string>();

            try
            {
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var addRuleResult = _iotConnectClient.Rule.Add(Mapper.Configuration.Mapper.Map <IOT.AddRuleModel>(request)).Result;

                    if (addRuleResult != null && !addRuleResult.status)
                    {
                        _logger.Error($"Notification is not added in iotconnect, Error: {addRuleResult.message}");
                        actionStatus.Success = false;
                        actionStatus.Message = addRuleResult.errorMessages[0].Message;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(addRuleResult.data.ruleGuid))
                        {
                            actionStatus.Data = Get(Guid.Parse(addRuleResult.data.ruleGuid.ToUpper()));
                        }
                    }
                }
                else
                {
                    var updateRuleResult = _iotConnectClient.Rule.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateRuleModel>(request)).Result;
                    if (updateRuleResult != null && !updateRuleResult.status)
                    {
                        _logger.Error($"Notification is not updated in iotconnect, Error: {updateRuleResult.message}");
                        actionStatus.Success = false;
                        actionStatus.Message = updateRuleResult.errorMessages[0].Message;
                    }
                    else
                    {
                        actionStatus.Data = Get(request.Guid.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "NotificationService.Manage " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
 public Entity.BaseResponse <bool> AcquireDevice(string deviceUniqueId)
 {
     Entity.BaseResponse <bool> response = new Entity.BaseResponse <bool>(true);
     try
     {
         Entity.ActionStatus result = _service.AcquireDevice(deviceUniqueId);
         response.IsSuccess = result.Success;
         response.Message   = result.Message;
         response.Data      = result.Success;
     }
     catch (Exception ex)
     {
         return(new Entity.BaseResponse <bool>(false, ex.Message));
     }
     return(response);
 }
 public Entity.BaseResponse <bool> UpdateStatus(string id, bool status)
 {
     Entity.BaseResponse <bool> response = new Entity.BaseResponse <bool>(true);
     try
     {
         Entity.ActionStatus result = _service.UpdateStatus(Guid.Parse(id), status);
         response.IsSuccess = result.Success;
         response.Message   = result.Message;
         response.Data      = result.Success;
     }
     catch (Exception ex)
     {
         return(new Entity.BaseResponse <bool>(false, ex.Message));
     }
     return(response);
 }
Exemple #8
0
        public Entity.ActionStatus DeleteImage(Guid id)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(false);
            try
            {
                var dbEntity = _generatorRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
                if (dbEntity == null)
                {
                    throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Device");
                }

                bool deleteStatus = DeleteGeneratorImage(id, dbEntity.Image);
                if (deleteStatus)
                {
                    dbEntity.Image       = "";
                    dbEntity.UpdatedDate = DateTime.Now;
                    dbEntity.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                    dbEntity.CompanyGuid = SolutionConfiguration.CompanyId;

                    actionStatus         = _generatorRepository.Manage(dbEntity);
                    actionStatus.Data    = dbEntity.Guid;
                    actionStatus.Success = true;
                    actionStatus.Message = "Image deleted successfully!";
                    if (!actionStatus.Success)
                    {
                        _logger.ErrorLog(new Exception($"Device is not updated in database, Error: {actionStatus.Message}")
                                         , this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = actionStatus.Message;
                    }
                }
                else
                {
                    actionStatus.Success = false;
                    actionStatus.Message = "Image not deleted!";
                }
                return(actionStatus);
            }
            catch (Exception ex)
            {
                _logger.InfoLog(Constants.ACTION_EXCEPTION, "DeviceManager.DeleteImage " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
Exemple #9
0
        public Entity.ActionStatus Manage(Entity.Rule request)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            try
            {
                if (request.Guid == null || request.Guid == Guid.Empty)
                {
                    var addRuleResult = _iotConnectClient.Rule.Add(Mapper.Configuration.Mapper.Map <IOT.AddRuleModel>(request)).Result;

                    if (addRuleResult != null && !addRuleResult.status)
                    {
                        _logger.ErrorLog(new Exception($"Rule is not added in iotconnect, Error: {addRuleResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = "Something Went Wrong!";
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(addRuleResult.data.ruleGuid))
                        {
                            actionStatus.Data = Get(Guid.Parse(addRuleResult.data.ruleGuid.ToUpper()));
                        }
                    }
                }
                else
                {
                    var updateRuleResult = _iotConnectClient.Rule.Update(request.Guid.ToString(), Mapper.Configuration.Mapper.Map <IOT.UpdateRuleModel>(request)).Result;
                    if (updateRuleResult != null && !updateRuleResult.status)
                    {
                        _logger.ErrorLog(new Exception($"Rule is not added in iotconnect, Error: {updateRuleResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                        actionStatus.Success = false;
                        actionStatus.Message = "Something Went Wrong!";
                    }
                    else
                    {
                        actionStatus.Data = Get(request.Guid.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
        public Entity.ActionStatus DeleteImage(Guid id)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(false);
            try
            {
                var dbEntity = _entityRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
                if (dbEntity == null)
                {
                    throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Entity");
                }

                bool deleteStatus = DeleteEntityImage(id, dbEntity.Image);
                if (deleteStatus)
                {
                    dbEntity.Image       = "";
                    dbEntity.UpdatedDate = DateTime.Now;
                    dbEntity.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                    dbEntity.CompanyGuid = SolutionConfiguration.CompanyId;

                    actionStatus         = _entityRepository.Manage(dbEntity);
                    actionStatus.Data    = Mapper.Configuration.Mapper.Map <Model.Entity, Entity.Entity>(dbEntity);
                    actionStatus.Success = true;
                    actionStatus.Message = "Image deleted successfully!";
                    if (!actionStatus.Success)
                    {
                        _logger.Error($"Entity is not updated in database, Error: {actionStatus.Message}");
                        actionStatus.Success = false;
                        actionStatus.Message = actionStatus.Message;
                    }
                }
                else
                {
                    actionStatus.Success = false;
                    actionStatus.Message = "Image not deleted!";
                }
                return(actionStatus);
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "EntityManager.DeleteImage " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
Exemple #11
0
 public ActionStatus Manage(Entity.AddCompanyRequest request)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         if (request.Guid == null || request.Guid == Guid.Empty)
         {
             request.CreatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
             request.CreatedDate = DateTime.Now;
             actionStatus        = _companyRepository.Manage(request);
             actionStatus.Data   = Mapper.Configuration.Mapper.Map <Model.Company, Entity.Company>(actionStatus.Data);
             if (!actionStatus.Success)
             {
                 _logger.ErrorLog(new Exception($"Company is not added in solution database, Error: {actionStatus.Message}")
                                  , this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             }
         }
         else
         {
             var olddbCompany = _companyRepository.GetByUniqueId(x => x.Guid == request.Guid);
             if (olddbCompany == null)
             {
                 throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Company");
             }
             request.CreatedDate = olddbCompany.CreatedDate;
             request.CreatedBy   = olddbCompany.CreatedBy.Value;
             request.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
             request.UpdatedDate = DateTime.Now;
             actionStatus        = _companyRepository.Manage(request);
             actionStatus.Data   = Mapper.Configuration.Mapper.Map <Model.Company, Entity.Company>(actionStatus.Data);
             if (!actionStatus.Success)
             {
                 _logger.ErrorLog(new Exception($"Company is not added in solution database, Error: {actionStatus.Message}")
                                  , this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             }
         }
     }
     catch (Exception ex)
     {
         _logger.InfoLog(Constants.ACTION_EXCEPTION, "Company.InsertCompany " + ex);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
Exemple #12
0
 public ActionStatus VerifyKit(KitVerifyRequest request, bool isEdit = false)
 {
     Entity.ActionStatus result = new Entity.ActionStatus();
     try
     {
         result = _hardwareKitRepository.VerifyHardwareKit(request, isEdit);
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         return(new Entity.ActionStatus
         {
             Success = false,
             Message = ex.Message
         });
     }
     return(result);
 }
Exemple #13
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
                });
            }
        }
 public Entity.ActionStatus Delete(Guid id)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbGreenHouse = _greenHouseRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbGreenHouse == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : GreenHouse");
         }
         var dbCrop   = _cropRepository.FindBy(x => x.GreenHouseGuid.Equals(id) && x.IsDeleted.Equals(false)).FirstOrDefault();
         var dbDevice = _deviceRepository.FindBy(x => x.GreenHouseGuid.Equals(id) && x.IsDeleted.Equals(false)).FirstOrDefault();
         if (dbCrop == null && dbDevice == null)
         {
             var deleteEntityResult = _iotConnectClient.GreenHouse.Delete(id.ToString()).Result;
             if (deleteEntityResult != null && deleteEntityResult.status)
             {
                 dbGreenHouse.IsDeleted   = true;
                 dbGreenHouse.UpdatedDate = DateTime.Now;
                 dbGreenHouse.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                 return(_greenHouseRepository.Update(dbGreenHouse));
             }
             else
             {
                 _logger.ErrorLog(new Exception($"GreenHouse is not deleted from iotconnect, Error: {deleteEntityResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                 actionStatus.Success = false;
                 actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteEntityResult.errorMessages);
             }
         }
         else
         {
             _logger.ErrorLog(new Exception($"GreenHouse is not deleted from solution database.Crop/Device exists, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             actionStatus.Success = false;
             actionStatus.Message = "GreenHouse is not deleted from solution database.Crop/Device exists";
         }
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
Exemple #15
0
        public Entity.ActionStatus ValidateCompany(Entity.ValidateCompanyRequest requestData)
        {
            Entity.ActionStatus response = new Entity.ActionStatus(true);
            try
            {
                Entity.BaseResponse <bool> validateResult = new Entity.BaseResponse <bool>(false);
                validateResult = _subscriberHelper.ValidateCompany(requestData);

                response.Success = validateResult.IsSuccess;
                response.Message = validateResult.Message;
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public Entity.ActionStatus VerifyKit(Entity.KitVerifyRequest request, bool isEdit = false)
        {
            var result = new Entity.ActionStatus();

            try
            {
                result = _hardwareKitRepository.VerifyHardwareKit(request, isEdit);
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "HardwareKit.Verify " + ex);
                return(new Entity.ActionStatus
                {
                    Success = false,
                    Message = ex.Message
                });
            }
            return(result);
        }
 public Entity.ActionStatus UpdateStatus(Guid id, bool status)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbRole = _roleRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbRole == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Role");
         }
         var updateRoleStatusResult = _iotConnectClient.Role.UpdateRoleStatus(id.ToString(), status).Result;
         if (updateRoleStatusResult != null && updateRoleStatusResult.status)
         {
             var userRole = _userRepository.FindBy(x => x.RoleGuid.Equals(id)).FirstOrDefault();
             if (userRole == null)
             {
                 dbRole.IsActive    = status;
                 dbRole.UpdatedDate = DateTime.Now;
                 dbRole.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                 return(_roleRepository.Update(dbRole));
             }
             else
             {
                 _logger.Error($"Role is not updated in solution database.User exists, Error: {actionStatus.Message}");
                 actionStatus.Success = false;
                 actionStatus.Message = "User is allocated with this role, you can't update status!";
             }
         }
         else
         {
             _logger.Error($"Role is not updated in iotconnect, Error: {updateRoleStatusResult.message}");
             actionStatus.Success = false;
             actionStatus.Message = new UtilityHelper().IOTResultMessage(updateRoleStatusResult.errorMessages);
         }
     }
     catch (Exception ex)
     {
         _logger.Error(Constants.ACTION_EXCEPTION, "RoleService.Delete " + ex);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
Exemple #18
0
 public Entity.ActionStatus Delete(Guid id)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbLocation = _locationRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbLocation == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Location");
         }
         var dbGenerator = _generatorRepository.FindBy(x => x.LocationGuid.Equals(id)).FirstOrDefault();
         if (dbGenerator == null)
         {
             var deleteEntityResult = _iotConnectClient.Entity.Delete(id.ToString()).Result;
             if (deleteEntityResult != null && deleteEntityResult.status)
             {
                 dbLocation.IsDeleted   = true;
                 dbLocation.UpdatedDate = DateTime.Now;
                 dbLocation.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                 return(_locationRepository.Update(dbLocation));
             }
             else
             {
                 _logger.ErrorLog(new Exception($"Location is not deleted from iotconnect, Error: {deleteEntityResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                 actionStatus.Success = false;
                 actionStatus.Message = new UtilityHelper().IOTResultMessage(deleteEntityResult.errorMessages);
             }
         }
         else
         {
             _logger.ErrorLog(new Exception($"Location is not deleted in solution database.Generator exists, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             actionStatus.Success = false;
             actionStatus.Message = "Location is not deleted in solution database.Generator exists";
         }
     }
     catch (Exception ex)
     {
         _logger.InfoLog(Constants.ACTION_EXCEPTION, "Location.Delete " + ex);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
 public Entity.ActionStatus UpdateStatus(Guid id, bool status)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbUser = _userRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbUser == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : User");
         }
         try
         {
             var updateUserStatusResult = _iotConnectClient.User.UpdateUserStatus(dbUser.Guid.ToString(), status).Result;
             if (updateUserStatusResult != null && updateUserStatusResult.status)
             {
                 dbUser.IsActive    = status;
                 dbUser.UpdatedDate = DateTime.Now;
                 dbUser.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                 return(_userRepository.Update(dbUser));
             }
             else
             {
                 _logger.ErrorLog(new Exception($"User status is not updated in iotconnect, Error: {updateUserStatusResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
                 actionStatus.Success = false;
                 actionStatus.Message = new UtilityHelper().IOTResultMessage(updateUserStatusResult.errorMessages);//"Something Went Wrong!";
             }
         }
         catch (IoTConnectException ex)
         {
             _logger.ErrorLog(ex, "UserManager.Delete " + ex);
             actionStatus.Success = false;
             actionStatus.Message = ex.Message;
         }
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, "UserManager.Delete " + ex);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
 public Entity.ActionStatus UpdateStatus(Guid id, bool status)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbDeviceType = _deviceTypeRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbDeviceType == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : DeviceType");
         }
         try
         {
             var dbDevice = _deviceRepository.FindBy(x => x.TypeGuid.Equals(id) && !x.IsDeleted).FirstOrDefault();
             if (dbDevice == null)
             {
                 dbDeviceType.IsActive    = status;
                 dbDeviceType.UpdatedDate = DateTime.Now;
                 dbDeviceType.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                 return(_deviceTypeRepository.Update(dbDeviceType));
             }
             else
             {
                 _logger.Error($"Device Type is not updated in solution database.Device exists, Error: {actionStatus.Message}");
                 actionStatus.Success = false;
                 actionStatus.Message = "Asset Type status cannot be updated because device exists";
             }
         }
         catch (IoTConnectException ex)
         {
             _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             actionStatus.Success = false;
             actionStatus.Message = ex.Message;
         }
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
Exemple #21
0
 public Entity.ActionStatus DeleteMediaFile(Guid generatorId, Guid?fileId)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbMediaFile = _generatorRepository.FindBy(x => x.Guid.Equals(generatorId)).FirstOrDefault();
         if (dbMediaFile == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : MediaFile");
         }
         return(_generatorRepository.DeleteMediaFiles(generatorId, fileId));
     }
     catch (Exception ex)
     {
         _logger.InfoLog(Constants.ACTION_EXCEPTION, "GeneratorService.DeleteMediaFile " + ex);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
 public Entity.ActionStatus UpdateStatus(Guid id, bool status)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var dbGreenHouse = _greenHouseRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
         if (dbGreenHouse == null)
         {
             throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : GreenHouse");
         }
         else
         {
             dbGreenHouse.IsActive    = status;
             dbGreenHouse.UpdatedDate = DateTime.Now;
             dbGreenHouse.UpdatedBy   = SolutionConfiguration.CurrentUserId;
             return(_greenHouseRepository.Update(dbGreenHouse));
         }
         //var dbCrop = _cropRepository.FindBy(x => x.GreenHouseGuid.Equals(id)).FirstOrDefault();
         //var dbDevice = _deviceRepository.FindBy(x => x.GreenHouseGuid.Equals(id)).FirstOrDefault();
         //if (dbCrop == null && dbDevice == null)
         //{
         //    dbGreenHouse.IsActive = status;
         //    dbGreenHouse.UpdatedDate = DateTime.Now;
         //    dbGreenHouse.UpdatedBy = SolutionConfiguration.CurrentUserId;
         //    return _greenHouseRepository.Update(dbGreenHouse);
         //}
         //else
         //{
         //    _logger.ErrorLog(new Exception($"GreenHouse is not updated from solution database.Crop/Device exists, Error: {actionStatus.Message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         //    actionStatus.Success = false;
         //    actionStatus.Message = "GreenHouse is not updated from solution database.Crop/Device exists";
         //}
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
Exemple #23
0
        public Entity.ActionStatus UpdateStatus(Guid id, bool status)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            try
            {
                var dbEntity = _entityRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
                if (dbEntity == null)
                {
                    throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : Facility");
                }

                var dbChildEntity = _entityRepository.FindBy(x => x.ParentEntityGuid.Equals(id) && !x.IsDeleted).FirstOrDefault();
                var dbDevice      = _deviceRepository.FindBy(x => x.EntityGuid.Equals(id) || (dbChildEntity != null && x.EntityGuid.Equals(dbChildEntity.Guid))).FirstOrDefault();
                if (dbDevice == null && dbChildEntity == null)
                {
                    dbEntity.IsActive    = status;
                    dbEntity.UpdatedDate = DateTime.Now;
                    dbEntity.UpdatedBy   = SolutionConfiguration.CurrentUserId;
                    return(_entityRepository.Update(dbEntity));
                }
                else if (dbChildEntity != null)
                {
                    _logger.ErrorLog(new Exception($"Facility is not updated in solution database.Zone exists, Error: {actionStatus.Message}"));
                    actionStatus.Success = false;
                    actionStatus.Message = "Facility is not updated in solution database.Zone exists";
                }
                else
                {
                    _logger.ErrorLog(new Exception($"Facility is not updated in solution database.Sensor exists, Error: {actionStatus.Message}"));
                    actionStatus.Success = false;
                    actionStatus.Message = "Facility is not updated in solution database.Sensor exists";
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
Exemple #24
0
 public Entity.ActionStatus TelemetrySummary_HourWise()
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         _logger.InfoLog(LogHandler.Constants.ACTION_ENTRY, null, "", "", this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         using (var sqlDataAccess = new SqlDataAccess(ConnectionString))
         {
             List <DbParameter> parameters = new List <DbParameter>();
             sqlDataAccess.ExecuteNonQuery(sqlDataAccess.CreateCommand("[TelemetrySummary_HourWise_Add]", CommandType.StoredProcedure, null), parameters.ToArray());
         }
         _logger.InfoLog(LogHandler.Constants.ACTION_EXIT, null, "", "", this.GetType().Name, MethodBase.GetCurrentMethod().Name);
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
Exemple #25
0
        public Entity.ActionStatus UpdateStatus(Guid id, string status)
        {
            Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
            try
            {
                var dbElevatorMaintenance = _deviceMaintenanceRepository.FindBy(x => x.Guid.Equals(id)).FirstOrDefault();
                if (dbElevatorMaintenance == null)
                {
                    throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : DeviceMaintenance");
                }

                return(_deviceMaintenanceRepository.Update(dbElevatorMaintenance));
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "DeviceMaintenance.UpdateStatus " + ex);
                actionStatus.Success = false;
                actionStatus.Message = ex.Message;
            }
            return(actionStatus);
        }
Exemple #26
0
 public Entity.ActionStatus UpdateStatus(Guid id, bool status)
 {
     Entity.ActionStatus actionStatus = new Entity.ActionStatus(true);
     try
     {
         var updateRuleStatusResult = _iotConnectClient.Rule.UpdateRuleStatus(id.ToString(), status).Result;
         if (updateRuleStatusResult != null && !updateRuleStatusResult.status)
         {
             _logger.ErrorLog(new Exception($"Rule status is not updated in iotconnect, Error: {updateRuleStatusResult.message}"), this.GetType().Name, MethodBase.GetCurrentMethod().Name);
             actionStatus.Success = false;
             actionStatus.Message = new UtilityHelper().IOTResultMessage(updateRuleStatusResult.errorMessages);
         }
     }
     catch (Exception ex)
     {
         _logger.ErrorLog(ex, this.GetType().Name, MethodBase.GetCurrentMethod().Name);
         actionStatus.Success = false;
         actionStatus.Message = ex.Message;
     }
     return(actionStatus);
 }
 public Entity.BaseResponse <bool> UpdateStatus(Guid id, bool status)
 {
     Entity.BaseResponse <bool> response = new Entity.BaseResponse <bool>(true);
     try
     {
         if (id.Equals(SolutionConfiguration.CurrentUserId))
         {
             return(new Entity.BaseResponse <bool>(false, "You can't change your own status!"));
         }
         Entity.ActionStatus result = _service.UpdateStatus(id, status);
         response.IsSuccess = result.Success;
         response.Message   = result.Message;
         response.Data      = result.Success;
     }
     catch (Exception ex)
     {
         base.LogException(ex);
         return(new Entity.BaseResponse <bool>(false, ex.Message));
     }
     return(response);
 }
        public Entity.BaseResponse <bool> Upload(List <Microsoft.AspNetCore.Http.IFormFile> files, string generatorId)
        {
            Entity.BaseResponse <bool> response = new Entity.BaseResponse <bool>(true);
            try
            {
                if (files.Count > 0)
                {
                    Entity.ActionStatus status = _service.UploadFiles(files, generatorId);

                    response.IsSuccess = status.Success;
                    response.Message   = status.Message;
                    response.Data      = status.Success;
                }
            }
            catch (Exception ex)
            {
                base.LogException(ex);
                return(new Entity.BaseResponse <bool>(false, ex.Message));
            }
            return(response);
        }
Exemple #29
0
        public Entity.ActionStatus ChangePassword(ChangePasswordRequest request)
        {
            var result = new Entity.ActionStatus();

            try
            {
                var adminUser = _adminUserRepository.FindBy(x => x.Email.Equals(request.Email)).FirstOrDefault();

                if (adminUser != null)
                {
                    if (adminUser.Password.Equals(request.OldPassword))
                    {
                        adminUser.Password    = request.NewPassword;
                        adminUser.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                        adminUser.UpdatedDate = DateTime.Now;

                        result = _adminUserRepository.Update(adminUser);

                        result.Data = Mapper.Configuration.Mapper.Map <Model.AdminUser, Entity.AdminUserResponse>(result.Data);
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = "Old Password Is Incorrect.";
                        result.Data    = null;
                    }
                }
                else
                {
                    result.Success = false;
                    result.Message = "User Not Found.";
                    result.Data    = null;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(Constants.ACTION_EXCEPTION, "AdminUserService.ChangePassword " + ex);
            }
            return(result);
        }
Exemple #30
0
        public Entity.ActionStatus Manage(Entity.CompanyConfig companyConfig)
        {
            try
            {
                var dbCompanyConfig = Mapper.Configuration.Mapper.Map <Entity.CompanyConfig, Model.CompanyConfig>(companyConfig);
                Entity.ActionStatus actionStatus = null;
                if (dbCompanyConfig.Guid == Guid.Empty)
                {
                    dbCompanyConfig.CompanyGuid = component.helper.SolutionConfiguration.CompanyId;
                    dbCompanyConfig.Guid        = Guid.NewGuid();
                    dbCompanyConfig.CreatedDate = DateTime.Now;
                    dbCompanyConfig.CreatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                    actionStatus = _companyConfigRepository.Insert(dbCompanyConfig);
                }
                else
                {
                    var olddbCompanyConfig = _companyConfigRepository.GetByUniqueId(x => x.Guid == dbCompanyConfig.Guid);
                    if (olddbCompanyConfig == null)
                    {
                        throw new NotFoundCustomException($"{CommonException.Name.NoRecordsFound} : CompanyConfig");
                    }

                    dbCompanyConfig.CreatedDate = olddbCompanyConfig.CreatedDate;
                    dbCompanyConfig.CreatedBy   = olddbCompanyConfig.CreatedBy; //TODO: Need To change later with session userid
                    dbCompanyConfig.UpdatedDate = DateTime.Now;
                    dbCompanyConfig.UpdatedBy   = component.helper.SolutionConfiguration.CurrentUserId;
                    actionStatus = _companyConfigRepository.Update(dbCompanyConfig);
                }
                return(actionStatus);
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex, "CompanyConfig.Manage " + ex);
                return(new Entity.ActionStatus
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }