public JsonResult Create()
        {
            String name      = Request.Form["name"];
            string imageName = Request.Form["OrganizationImage"];

            //change path
            System.IO.File.Move(Server.MapPath("~\\Assets\\Temp\\") + imageName, Server.MapPath("~\\Assets\\") + imageName);

            Organization      organization = new Organization();
            OrganizationImage oi           = new OrganizationImage();

            oi.Image          = imageName;
            organization.name = name;
            organization.OrganizationImage = oi;

            try
            {
                db.Organizations.Add(organization);
                db.Organization_Images.Add(oi);
                db.SaveChanges();
                return(Json(new { Message = name, success = true }));
            }
            catch (Exception ex)
            {
                return(Json(new { Message = "Problem in creating organization: " + ex }));
            }
        }
Exemplo n.º 2
0
        public ContentResult CkEditorUploadFileResourceForOrganizationDescription(OrganizationPrimaryKey organizationPrimaryKey, CkEditorImageUploadViewModel viewModel)
        {
            var fileResourceInfo = FileResourceModelExtensions.CreateNewFromHttpPostedFileAndSave(viewModel.upload, CurrentFirmaSession);
            var organization     = organizationPrimaryKey.EntityObject;
            var ppImage          = new OrganizationImage(organization, fileResourceInfo);

            HttpRequestStorage.DatabaseEntities.AllOrganizationImages.Add(ppImage);
            return(Content(viewModel.GetCkEditorJavascriptContentToReturn(fileResourceInfo)));
        }
Exemplo n.º 3
0
        public ActionResult UpdateOrganization(OrganizationInformationViewModel model, HttpPostedFileBase file)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var organization = new Organization()
                {
                    Id          = model.Id,
                    AboutInfo   = model.AboutInfo,
                    Name        = model.Name,
                    PhoneNumber = model.PhoneNumber
                };

                // TODO: Extract this logic somewhere
                if (file != null)
                {
                    var extension = file.FileName.Substring(file.FileName.LastIndexOf("."));

                    if (!this.organizationImages.ValidateFileExtention(extension))
                    {
                        this.ModelState.AddModelError(string.Empty, $"The Image Should be {GlobalConstants.JpgFileExtension} or {GlobalConstants.PngFileExtension}.");
                        return(this.View("Index", model));
                    }

                    var imageName         = Guid.NewGuid();
                    var savePath          = $"/Images/{organization.Name}/{imageName}{extension}";
                    var saveDirPathMapped = System.IO.Path.GetDirectoryName(this.Server.MapPath(savePath));
                    if (!System.IO.Directory.Exists(saveDirPathMapped))
                    {
                        System.IO.Directory.CreateDirectory(saveDirPathMapped);
                    }

                    file.SaveAs(this.Server.MapPath(savePath));

                    var image = new OrganizationImage()
                    {
                        Name = imageName.ToString(),
                        Url  = savePath
                    };

                    organization.OrganizationImage = image;
                }

                this.organizations.Update(organization);
                return(this.RedirectToAction(x => x.Index()));
            }

            return(this.View("Index", model));
        }
Exemplo n.º 4
0
        public IHttpActionResult UpdateOrganizationDescription(string apiKey, [FromBody] OrganizationDescriptionDto organizationDto)
        {
            Check.Require(apiKey == FirmaWebApiConfiguration.PsInfoApiKey, "Unrecognized api key!");
            var organization = _databaseEntities.Organizations.SingleOrDefault(x => x.OrganizationID == organizationDto.OrganizationID);

            if (organization == null)
            {
                var message = $"Performance Measure with ID = {organizationDto.OrganizationID} not found";
                return(NotFound());
            }

            organization.Description = organizationDto.Description;

            var fileResourceDtos      = organizationDto.FileResources;
            var fileResourceMimeTypes = fileResourceDtos.ToDictionary(x => new { x.FileResourceGUID, x.FileResourceMimeTypeName },
                                                                      x => MapFileResourceMimeTypeNameToFileResourceMimeType(x.FileResourceMimeTypeName));

            if (fileResourceMimeTypes.Values.Any(x => x == null))
            {
                var errors =
                    fileResourceMimeTypes.Where(x => x.Value == null).Select(x =>
                                                                             $"Invalid File Resource Mime Type '{x.Key.FileResourceMimeTypeName}' for '{x.Key.FileResourceGUID}'").ToList();
                return(BadRequest(string.Join("\r\n", errors)));
            }

            // Remove all of these, too hard to merge nicely
            _databaseEntities.AllFileResourceDatas.RemoveRange(organization.OrganizationImages.Select(x => x.FileResourceInfo.FileResourceData));
            _databaseEntities.AllFileResourceInfos.RemoveRange(organization.OrganizationImages.Select(x => x.FileResourceInfo));
            _databaseEntities.AllOrganizationImages.RemoveRange(organization.OrganizationImages);

            var peopleDictionary           = _databaseEntities.People.ToDictionary(x => x.Email);
            var organizationImagesToUpdate = fileResourceDtos.Select(x =>
            {
                var fileResourceMimeTypeID = fileResourceMimeTypes.Single(y => y.Key.FileResourceGUID == x.FileResourceGUID).Value.FileResourceMimeTypeID;
                var personID         = peopleDictionary.ContainsKey(x.Email) ? peopleDictionary[x.Email].PersonID : 5278;
                var fileResourceInfo = new FileResourceInfo(fileResourceMimeTypeID, x.OriginalBaseFilename, x.OriginalFileExtension, x.FileResourceGUID, personID, x.CreateDate);
                fileResourceInfo.FileResourceDatas.Add(new FileResourceData(fileResourceInfo.FileResourceInfoID, x.FileResourceData));
                var organizationImage = new OrganizationImage(organization, fileResourceInfo);
                return(organizationImage);
            }).ToList();

            _databaseEntities.SaveChangesWithNoAuditing(Tenant.ActionAgendaForPugetSound.TenantID);
            var organizationReloaded = new OrganizationDto(organization);

            return(Ok(organizationReloaded));
        }
        public ActionResult AddImage(int orgId)
        {
            Image img = new Image();

            img.ImageUrl = Request.Files[0].FileName;
            imagerep.Add(img);

            string ImagePath = ConfigurationManager.AppSettings["ImagePath"] + "/" + img.Id + "_" + img.ImageUrl;

            Request.Files[0].SaveAs(ImagePath);

            OrganizationImage orgimage = new OrganizationImage();

            orgimage.ImageId        = img.Id;
            orgimage.OrganizationId = orgId;
            orgimagerep.Add(orgimage);


            return(RedirectToAction("Detail", new { id = orgId }));
        }
        public ActionResult UpdateOrganization(OrganizationInformationViewModel model, HttpPostedFileBase file)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var organization = new Organization()
                {
                    Id = model.Id,
                    AboutInfo = model.AboutInfo,
                    Name = model.Name,
                    PhoneNumber = model.PhoneNumber
                };

                // TODO: Extract this logic somewhere
                if (file != null)
                {
                    var extension = file.FileName.Substring(file.FileName.LastIndexOf("."));

                    if (!this.organizationImages.ValidateFileExtention(extension))
                    {
                        this.ModelState.AddModelError(string.Empty, $"The Image Should be {GlobalConstants.JpgFileExtension} or {GlobalConstants.PngFileExtension}.");
                        return this.View("Index", model);
                    }

                    var imageName = Guid.NewGuid();
                    var savePath = $"/Images/{organization.Name}/{imageName}{extension}";
                    var saveDirPathMapped = System.IO.Path.GetDirectoryName(this.Server.MapPath(savePath));
                    if (!System.IO.Directory.Exists(saveDirPathMapped))
                    {
                        System.IO.Directory.CreateDirectory(saveDirPathMapped);
                    }

                    file.SaveAs(this.Server.MapPath(savePath));

                    var image = new OrganizationImage()
                    {
                        Name = imageName.ToString(),
                        Url = savePath
                    };

                    organization.OrganizationImage = image;
                }

                this.organizations.Update(organization);
                return this.RedirectToAction(x => x.Index());
            }

            return this.View("Index", model);
        }