Пример #1
0
 public Entity.SaveCompanyResponse CreateCompany(Entity.SaveCompanyRequest requestData)
 {
     InitSubscriptionToken();
     Entity.SubsciberCompanyDetails existingConsumer = GetSubscriberDetails(requestData.SolutionCode, requestData.User.Email);
     if (existingConsumer != null && string.IsNullOrEmpty(existingConsumer.email))//Check email exists or not
     {
         using (var response = _httpClientHelper.Post <Entity.SaveCompanyRequest>(string.Concat(apiBaseURL, "solution/company"), requestData, _subcriptionAccessToken))
         {
             if ((int)response.StatusCode == (int)HttpStatusCode.OK)
             {
                 return(JsonConvert.DeserializeObject <Entity.SaveCompanyResponse>(response.Content.ReadAsStringAsync().Result));
             }
             else
             {
                 List <Entity.ErrorMessageResponse> errorMessage = JsonConvert.DeserializeObject <List <Entity.ErrorMessageResponse> >(response.Content.ReadAsStringAsync().Result);
                 if (errorMessage != null && errorMessage.Any())
                 {
                     throw new Exception(string.Format("{0}", errorMessage.FirstOrDefault().msg));
                 }
                 else
                 {
                     throw new Exception("Please try again. Something went wrong!!!");
                 }
             }
         }
     }
     else
     {
         throw new Exception("Email address already registered. Try with another email!!!");
     }
 }
        public Entity.ActionStatus SaveCompany(Entity.SaveCompanyRequest requestData)
        {
            Entity.ActionStatus response = new Entity.ActionStatus(true);
            try
            {
                requestData.User.PhoneCountryCode = requestData.User.PhoneCountryCode.Replace("+", "");
                Entity.SaveCompanyResponse saveResult = _subscriberHelper.CreateCompany(requestData);
                if (saveResult != null && saveResult.PaymentTransactionId != null)
                {
                    response.Data = saveResult;

                    Model.Company dbCompany = new Model.Company()
                    {
                        Guid         = Guid.Parse(saveResult.IoTConnectCompanyGuid),
                        Name         = requestData.User.CompanyName,
                        ContactNo    = requestData.User.PhoneCountryCode + "-" + requestData.User.Phone,
                        Address      = requestData.User.Address,
                        CountryGuid  = Guid.Parse(requestData.User.CountryId),
                        TimezoneGuid = Guid.Parse(requestData.User.TimezoneId),
                        StateGuid    = Guid.Parse(requestData.User.StateId),
                        City         = requestData.User.CityName,
                        PostalCode   = requestData.User.PostalCode
                    };
                    Entity.ActionStatus upStatus = _companyRepository.UpdateDetails(dbCompany);

                    Model.User objUser = new Model.User()
                    {
                        CompanyGuid  = Guid.Parse(saveResult.IoTConnectCompanyGuid),
                        Email        = requestData.User.Email,
                        ContactNo    = requestData.User.PhoneCountryCode + "-" + requestData.User.Phone,
                        FirstName    = requestData.User.FirstName,
                        LastName     = requestData.User.LastName,
                        TimeZoneGuid = Guid.Parse(requestData.User.TimezoneId),
                    };

                    var dbUser = _userRepository.FindBy(u => u.Email.Equals(objUser.Email) && u.CompanyGuid.Equals(objUser.CompanyGuid)).FirstOrDefault();
                    if (dbUser != null)
                    {
                        dbUser.ContactNo    = requestData.User.PhoneCountryCode + "-" + requestData.User.Phone;
                        dbUser.FirstName    = objUser.FirstName;
                        dbUser.LastName     = objUser.LastName;
                        dbUser.TimeZoneGuid = objUser.TimeZoneGuid;
                        _userRepository.Update(dbUser);
                    }

                    response.Success = true;
                    response.Message = "";
                }
                else
                {
                    if (saveResult != null)
                    {
                        response.Data = saveResult;
                    }
                    response.Success = false;
                    response.Message = "Something Went Wrong!";
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Пример #3
0
        public Entity.ActionStatus SaveCompany(Entity.SaveCompanyRequest requestData)
        {
            Entity.ActionStatus response = new Entity.ActionStatus(true);
            try
            {
                requestData.User.PhoneCountryCode = requestData.User.PhoneCountryCode.Replace("+", "");
                Entity.SaveCompanyResponse saveResult = _subscriberHelper.CreateCompany(requestData);
                if (saveResult != null && saveResult.PaymentTransactionId != null)
                {
                    response.Data = saveResult;

                    Model.Company dbCompany = new Model.Company()
                    {
                        Guid         = Guid.Parse(saveResult.IoTConnectCompanyGuid),
                        Name         = requestData.User.CompanyName,
                        ContactNo    = requestData.User.PhoneCountryCode + "-" + requestData.User.Phone,
                        Address      = requestData.User.Address,
                        CountryGuid  = Guid.Parse(requestData.User.CountryId),
                        TimezoneGuid = Guid.Parse(requestData.User.TimezoneId),
                        StateGuid    = Guid.Parse(requestData.User.StateId),
                        City         = requestData.User.CityName,
                        PostalCode   = requestData.User.PostalCode
                    };
                    Entity.ActionStatus upStatus = _companyRepository.UpdateDetails(dbCompany);

                    Model.User objUser = new Model.User()
                    {
                        CompanyGuid  = Guid.Parse(saveResult.IoTConnectCompanyGuid),
                        Email        = requestData.User.Email,
                        ContactNo    = requestData.User.PhoneCountryCode + "-" + requestData.User.Phone,
                        FirstName    = requestData.User.FirstName,
                        LastName     = requestData.User.LastName,
                        TimeZoneGuid = Guid.Parse(requestData.User.TimezoneId),
                    };

                    var dbUser = _userRepository.FindBy(u => u.Email.Equals(objUser.Email) && u.CompanyGuid.Equals(objUser.CompanyGuid)).FirstOrDefault();
                    if (dbUser != null)
                    {
                        dbUser.ContactNo    = requestData.User.PhoneCountryCode + "-" + requestData.User.Phone;
                        dbUser.FirstName    = objUser.FirstName;
                        dbUser.LastName     = objUser.LastName;
                        dbUser.TimeZoneGuid = objUser.TimeZoneGuid;
                        _userRepository.Update(dbUser);
                    }
                    else
                    {
                        //IOT.DataResponse<IOT.SearchUserResult> iotUsers = _iotConnectClient.User.AllCompanyUser(new IoTConnect.Model.SearchUserModel() { PageNo = 1, PageSize = 1, SearchText = objUser.Email }).Result;
                        //if (iotUsers != null && iotUsers.data != null && iotUsers.data.data != null && iotUsers.data.data.Any())
                        //{
                        //    var user = iotUsers.data.data.FirstOrDefault();
                        //    _userRepository.Insert(new Model.User()
                        //    {
                        //        CompanyGuid = objUser.CompanyGuid,
                        //        ContactNo = objUser.ContactNo,
                        //        Email = objUser.Email,
                        //        FirstName = objUser.FirstName,
                        //        LastName = objUser.LastName,
                        //        Guid = Guid.Parse(user.Guid),
                        //        TimeZoneGuid = objUser.TimeZoneGuid,
                        //        IsActive = true,
                        //        IsDeleted = false,
                        //        CreatedBy = Guid.NewGuid(),
                        //        CreatedDate = DateTime.Now,
                        //        GensetGuid = Guid.NewGuid(),
                        //        RoleGuid = Guid.Parse(user.RoleGuid),
                        //    });
                        //}
                    }
                    //Entity.ActionStatus userStatus = _userRepository.UpdateDetails(dbUser);

                    response.Success = true;
                    response.Message = "";
                }
                else
                {
                    if (saveResult != null)
                    {
                        response.Data = saveResult;
                    }
                    response.Success = false;
                    response.Message = "Something Went Wrong!";
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorLog(ex);
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }