Example #1
0
        public ActionResult AddOrganization(Organization _organization, string EncryptedOrganizationID)
        {
            string       ImagePath        = "";
            string       FaviconImagePath = "";
            Organization _org             = new Organization();

            if (EncryptedOrganizationID == "" || EncryptedOrganizationID == " ")
            {
                if (_organization.FaviconImageFile != null)
                {
                    _organization.FaviconImage = "fav.ico";
                }
                if (_organization.OrganizationImageFile != null)
                {
                    _organization.LogoImage = "Org" + Path.GetExtension(_organization.OrganizationImageFile.FileName);
                }
                else
                {
                    _organization.LogoImage = "Org.png";
                }
                _organization.OrganizationID = _clientService.AddOrganization(Mapper.Map <NEPService.ClientService.Organization>(_organization));
                //------- saving logo image
                string logoPathstring = _storageService.OrgainzationLogoDelete(Server.MapPath(GlobalConst.FolderName.Storage + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _organization.OrganizationID), Path.GetFileName(_organization.LogoImage));
                if (_organization.OrganizationImageFileContent != null)
                {
                    byte[] bytes = Convert.FromBase64String(_organization.OrganizationImageFileContent.Split(',')[1]);
                    if (System.IO.File.Exists(logoPathstring))
                    {
                        System.IO.File.Delete(logoPathstring);
                    }
                    using (System.IO.FileStream stream = new System.IO.FileStream(logoPathstring, System.IO.FileMode.Create))
                    {
                        stream.Write(bytes, 0, bytes.Length);
                        stream.Flush();
                    }
                }
                else
                {
                    SaveDefaultLogo(logoPathstring);
                }
                //-----------------
                if (_organization.FaviconImageFile != null)
                {
                    FaviconImagePath = _storageService.SetOrganizationStorageFaviconPath(Server.MapPath(GlobalConst.FolderName.Storage + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _organization.OrganizationID), _organization.FaviconImage);
                    _organization.FaviconImageFile.SaveAs(FaviconImagePath);
                }
                _org.Message = "Save SuccessFully";
            }
            else
            {
                _organization.OrganizationID = Convert.ToInt32(DecryptString(EncryptedOrganizationID));
                if (_organization.OrganizationImageFileContent != null)
                {
                    _organization.LogoImage = "Org" + Path.GetExtension(_organization.OrganizationImageFile.FileName);
                    //------- Saving logo image
                    string logoPathstring = _storageService.OrgainzationLogoDelete(Server.MapPath(GlobalConst.FolderName.Storage + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _organization.OrganizationID), Path.GetFileName(_organization.LogoImage));
                    byte[] bytes          = Convert.FromBase64String(_organization.OrganizationImageFileContent.Split(',')[1]);
                    if (System.IO.File.Exists(logoPathstring))
                    {
                        System.IO.File.Delete(logoPathstring);
                    }
                    using (System.IO.FileStream stream = new System.IO.FileStream(logoPathstring, System.IO.FileMode.Create))
                    {
                        stream.Write(bytes, 0, bytes.Length);
                        stream.Flush();
                    }
                    //--------------------------------
                    ImagePath = _storageService.SetOrganizationStoragePath(Server.MapPath(GlobalConst.FolderName.Storage + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _organization.OrganizationID), _organization.LogoImage);
                }
                else
                {
                    var _data = _clientService.GetOrganizationByID(_organization.OrganizationID);
                    _organization.LogoImage = _data.LogoImage;
                }

                if (_organization.FaviconImageFile != null)
                {
                    _organization.FaviconImage = "fav.ico";
                    FaviconImagePath           = _storageService.SetOrganizationStorageFaviconPath(Server.MapPath(GlobalConst.FolderName.Storage + GlobalConst.ConstantChar.DoubleBackSlash + GlobalConst.FolderName.Org + _organization.OrganizationID), _organization.FaviconImage);
                    _organization.FaviconImageFile.SaveAs(FaviconImagePath);
                }
                else
                {
                    var _data = _clientService.GetOrganizationByID(_organization.OrganizationID);
                    _organization.FaviconImage = _data.FaviconImage;
                }

                var OrganizationID = _clientService.UpdateOrganization(Mapper.Map <NEPService.ClientService.Organization>(_organization));
                _org.Message = "Update SuccessFully";
            }

            if (_organization.ThemeID != null)
            {
                setTheme(_organization.ThemeID.Value, _organization.OrganizationID, _organization.LogoImage, _organization.WebsiteName);
            }
            _org.EncryptedOrganizationID = EncryptString(_organization.OrganizationID.ToString());
            return(Json(_org));
        }