public ActionResult Organization(OrganizationViewModel orgViewModel)
        {
            if (orgViewModel.OrganizationType != 0)
                ValidateViewModel(orgViewModel, orgViewModel.OrganizationType);
            else
                ModelState.AddModelError("OrganizationType", "Please select the organization type.");
            if (ModelState.IsValid)
            {
                if (orgViewModel.IsQuickView)
                {
                    orgViewModel.NoOfQuickView = 1;
                    orgViewModel.QuickViewEnd = false;
                }

                var mappedModel = Mapper.Map<OrganizationViewModel, Organization>(orgViewModel);
                mappedModel.CreatedDate = mappedModel.UpdatedDate = DateTime.Now;
                mappedModel.IsHomeOrg = false;
                mappedModel.CreatedBy = mappedModel.UpdatedBy = SessionContext.CurrentUser.Id;
                mappedModel.LibraryFolders = new List<LibraryFolder>();
                var libFolder = new LibraryFolder();
                var libAsset = GetLibraryAsset(orgViewModel.DisplayPicture);
                ICollection<LibraryAsset> libAssetsColl = new Collection<LibraryAsset>();
                if (libAsset != null)
                    libAssetsColl.Add(libAsset);
                libFolder.LibraryAssets = libAssetsColl;
                mappedModel.LibraryFolders.Add(libFolder);
                mappedModel.Active = true;
                var organizationModel = _wcfService.InvokeService<IUserService, Organization>((svc) => svc.AddOrganization(mappedModel));
                if (organizationModel != null)
                {
                    var lFolder = organizationModel.LibraryFolders.FirstOrDefault(x => x.FolderName == "Assets");
                    SaveImageToDisk(lFolder, orgViewModel.DisplayPicture);
                    orgViewModel.CreationSuccessful = true;
                    orgViewModel.Message = "{0} saved successfully.Your account will be activated for use after the approval process is completed by us.".ToFormat(organizationModel.OrganizationName);
                    SessionContext.CurrentUser.OrganizationId = organizationModel.Id;
                }
            }
            else
            {
                ModelState.AddModelError("", "There was an error while saving. Please try again.");

            }
            return View(orgViewModel);
        }
 private void ValidateViewModel(OrganizationViewModel orgViewModel, int orgType)
 {
     if (orgType == (int)OrganizationType.New)
     {
         if (!orgViewModel.OrganizationName.Clean().IsNotEmpty())
             ModelState.AddModelError("OrganizationName", "Organization Name is mandatory.");
         if (!orgViewModel.OrganizationAddress.Clean().IsNotEmpty())
             ModelState.AddModelError("OrganizationAddress", "Organization Address is mandatory.");
         if (!orgViewModel.OrganizationMobile.HasValue)
             ModelState.AddModelError("OrganizationMobile", "Organization Mobile is mandatory.");
         if (!orgViewModel.OrganizationEmail.Clean().IsNotEmpty())
             ModelState.AddModelError("OrganizationEmail", "Organization Email is mandatory.");
         if (!orgViewModel.OrganizationContact.Clean().IsNotEmpty())
             ModelState.AddModelError("OrganizationContact", "Email Of Contact-Person is mandatory.");
         if (!orgViewModel.VerificationDate.HasValue && !orgViewModel.IsSelfie)
             ModelState.AddModelError("VerificationDate", "Verification Date is mandatory.");
         if (orgViewModel.OrganizationName.Clean().IsNotEmpty())
         {
             var isExist = CheckOrganizationExists(orgViewModel.OrganizationName.Clean());
             if (isExist)
                 ModelState.AddModelError("OrganizationName", "Organization name '{0}' is already present.".ToFormat(orgViewModel.OrganizationName));
         }
     }
     if (orgType == (int)OrganizationType.Registered)
     {
         if (!orgViewModel.ReferencedEmail.Clean().IsNotEmpty())
             ModelState.AddModelError("ReferencedEmail", "Referenced Email is mandatory.");
         if (orgViewModel.DepartmentId.HasValue)
             ModelState.AddModelError("DepartmentId", "Please select a department.");
         if (!orgViewModel.EmployeeIdOrg.Clean().IsNotEmpty())
             ModelState.AddModelError("EmployeeIdOrg", "Employee Id is mandatory.");
         if (orgViewModel.ReferencedEmail.Clean().IsNotEmpty())
         {
             var isPresent = CheckEmailExists(orgViewModel.ReferencedEmail);
             if (isPresent)
                 ModelState.AddModelError("ReferencedEmail", "The referenced email you entered does not exist.");
         }
     }
 }
 public ActionResult Organization()
 {
     var organizationViewModel = new OrganizationViewModel()
     {
         OrganizationDocumentViewModel = new OrganizationDocumentViewModel(),
         Department = GetDepartment(),
         OrganizationDocumentViewModels = new List<OrganizationDocumentViewModel>()
     };
     return View(organizationViewModel);
 }