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);
        }
Exemplo n.º 2
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);
        }