public CompanyProfileDto GetCompanyProfile()
        {
            using (EAharaDB context = new EAharaDB())
            {
                var dataItem = context.CompanyProfiles.FirstOrDefault(x => x.Id > 0);
                if (dataItem != null)
                {
                    if (dataItem != null)
                    {
                        CompanyProfileDto returndata = new CompanyProfileDto();
                        returndata.Id            = dataItem.Id;
                        returndata.Name          = dataItem.Name;
                        returndata.WhatsappNo    = dataItem.WhatsappNo;
                        returndata.TeleNo        = dataItem.TeleNo;
                        returndata.Address       = dataItem.Address;
                        returndata.Email         = dataItem.Email;
                        returndata.MobileNo      = dataItem.MobileNo;
                        returndata.Location      = dataItem.Location;
                        returndata.RegPoints     = dataItem.RegPoints;
                        returndata.BookingPoints = dataItem.BookingPoints;
                        returndata.Points        = dataItem.Points;
                        returndata.WalletLimit   = dataItem.WalletLimit;
                        returndata.ShareText     = dataItem.ShareText;

                        returndata.SMSID       = dataItem.SMSID;
                        returndata.SMSpassword = dataItem.SMSpassword;
                        returndata.SMSusername = dataItem.SMSusername;


                        return(returndata);
                    }
                }
                return(null);
            }
        }
        public bool SaveCompanyProfile(CompanyProfileDto dataDto)
        {
            if (dataDto != null)
            {
                using (EAharaDB context = new EAharaDB())
                {
                    if (dataDto.Id > 0)
                    {
                        {
                            var data = context.CompanyProfiles.FirstOrDefault(x => x.Id == dataDto.Id);
                            if (data != null)
                            {
                                data.Address       = dataDto.Address;
                                data.Name          = dataDto.Name;
                                data.MobileNo      = dataDto.MobileNo;
                                data.TeleNo        = dataDto.TeleNo;
                                data.Email         = dataDto.Email;
                                data.WhatsappNo    = dataDto.WhatsappNo;
                                data.Location      = dataDto.Location;
                                data.SMSID         = dataDto.SMSID;
                                data.SMSpassword   = dataDto.SMSpassword;
                                data.SMSusername   = dataDto.SMSusername;
                                data.WalletLimit   = dataDto.WalletLimit;
                                data.Points        = dataDto.Points;
                                data.BookingPoints = dataDto.BookingPoints;
                                data.RegPoints     = dataDto.RegPoints;
                                data.ShareText     = dataDto.ShareText;


                                context.SaveChanges();
                                return(true);
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        CompanyProfile company = new CompanyProfile();

                        company.Address       = dataDto.Address;
                        company.Name          = dataDto.Name;
                        company.MobileNo      = dataDto.MobileNo;
                        company.TeleNo        = dataDto.TeleNo;
                        company.Email         = dataDto.Email;
                        company.WhatsappNo    = dataDto.WhatsappNo;
                        company.Location      = dataDto.Location;
                        company.Points        = dataDto.Points;
                        company.BookingPoints = dataDto.BookingPoints;
                        company.RegPoints     = dataDto.RegPoints;
                        company.WalletLimit   = dataDto.WalletLimit;
                        company.ShareText     = dataDto.ShareText;

                        company.SMSID       = dataDto.SMSID;
                        company.SMSpassword = dataDto.SMSpassword;
                        company.SMSusername = dataDto.SMSusername;
                        context.CompanyProfiles.Add(company);

                        context.SaveChanges();
                        return(true);
                    }
                }
            }
            return(false);
        }
        public IActionResult CreateUpdateCompanyProfile([FromForm] CompanyProfileDto companyProfileDto)
        {
            try
            {
                var profileid = User.FindFirst(JwtRegisteredClaimNames.Sid).Value;
                // Validation
                if (companyProfileDto == null)
                {
                    return(BadRequest());
                }

                // Validate image
                int            MaxContentLength      = 1024 * 1024 * 5; //Size = 5 MB
                IList <string> AllowedFileExtensions = new List <string> {
                    "jpg", "gif", "png"
                };
                var  extension       = "";
                bool flagProcessLogo = companyProfileDto.Logo != null;

                if (flagProcessLogo)
                {
                    var ext = companyProfileDto.Logo.FileName.Substring(companyProfileDto.Logo.FileName.LastIndexOf('.') + 1);
                    extension = ext.ToLower();
                    if (!AllowedFileExtensions.Contains(extension))
                    {
                        var message = string.Format("Please Upload image of type .jpg,.gif,.png.");
                        _logger.LogInformation(message);
                        return(BadRequest(message));
                    }
                    else if (companyProfileDto.Logo.Length > MaxContentLength)
                    {
                        var message = string.Format("Please Upload a file upto 5 mb.");
                        _logger.LogInformation(message);
                        return(BadRequest(message));
                    }
                }

                // Create/update
                var flagCreate     = false;
                var companyProfile = _companyProfileRepository.Get(profileid);
                if (companyProfile == null)
                {
                    flagCreate     = true;
                    companyProfile = new CompanyProfile
                    {
                        UserId = profileid
                    };
                }
                companyProfile.Name        = companyProfileDto.Name;
                companyProfile.Description = companyProfileDto.Description;
                companyProfile.Website     = companyProfileDto.Website;
                companyProfile.Adress      = companyProfileDto.Adress;

                if (flagProcessLogo)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        companyProfileDto.Logo.CopyTo(memoryStream);
                        companyProfile.Logo = memoryStream.ToArray();
                    }
                    companyProfile.LogoExtension = extension;
                }

                // Save to DB
                if (flagCreate)
                {
                    _companyProfileRepository.Add(companyProfile);
                }
                if (!_companyProfileRepository.Save())
                {
                    return(StatusCode(500, "A problem happend while handeling your request."));
                }

                var companyProfileDtoToReturn = Mapper.Map <CompanyProfileViewDto>(companyProfile);

                return(CreatedAtRoute("GetCompanyProfile", companyProfileDtoToReturn));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"An exception was thrown: ", ex);
                return(StatusCode(500, "A problem happend while handeling your request."));
            }
        }