Beispiel #1
0
        public ActionResult ApiUpdateLogo(HttpPostedFileBase file)
        {
            if (file == null && file.ContentLength == 0)
            {
                return(View("~/Views/Template/UpdateLogo.cshtml", new TemplateServiceUpdateLogoModel(this.MobiContext, "You did not provided file for upload")));
            }

            if (!file.FileName.Contains(".png"))
            {
                return(View("~/Views/Template/UpdateLogo.cshtml", new TemplateServiceUpdateLogoModel(this.MobiContext, "Error. You must provide file with .png extension")));
            }

            byte[] data = null;
            using (MemoryStream ms = new MemoryStream())
            {
                file.InputStream.CopyTo(ms);
                data = ms.GetBuffer();
            }

            if (data == null)
            {
                return(View("~/Views/Template/UpdateLogo.cshtml", new TemplateServiceUpdateLogoModel(this.MobiContext, "Error with converting file")));
            }

            ServiceLogo serviceLogo = ServiceLogo.LoadByService(this.MobiContext.Service.ServiceData);

            if (serviceLogo == null)
            {
                serviceLogo = new ServiceLogo(-1, this.MobiContext.Service.ServiceData, data, DateTime.Now, DateTime.Now);
                serviceLogo.Insert();
                this.MobiContext.Service.Init();
                return(View("~/Views/Template/UpdateLogo.cshtml", new TemplateServiceUpdateLogoModel(this.MobiContext, "Success! Logo is inserted. ")));
            }
            else
            {
                serviceLogo.Data = data;
                serviceLogo.Update();
                this.MobiContext.Service.Init();
                return(View("~/Views/Template/UpdateLogo.cshtml", new TemplateServiceUpdateLogoModel(this.MobiContext, "Success! Logo is updated. ")));
            }
        }
Beispiel #2
0
        } // Worker_DoWork

        private Image SafeLoadLogo(ServiceLogo logo)
        {
            return(logo.GetImage(LogoSize.Size64, true));
        } // SafeLoadLogo