Example #1
0
        public JsonResult Index(DelegateModel objDelegateModel, int acid)
        {
            bool bStatusFlag     = false;
            int  nPatrialSave    = 0;
            var  ErrorDictionary = new Dictionary <string, string>();

            Common.Common    objCommon           = new Common.Common();
            LoginUserDetails objLoginUserDetails = null;

            try
            {
                if (!objCommon.ValidateCSRFForAJAX())
                {
                    return(Json(new
                    {
                        status = false,
                        msg = ErrorDictionary
                    }, JsonRequestBehavior.AllowGet));
                }
                objLoginUserDetails = (LoginUserDetails)Common.Common.GetSessionValue(ConstEnum.SessionValue.UserDetails);

                if (ModelState.IsValid)
                {
                    ViewBag.UserInfoIdFrom        = objDelegateModel.UserInfoIdFrom;
                    ViewBag.UserInfoIdTo          = objDelegateModel.UserInfoIdTo;
                    ViewBag.DelegationFrom        = objDelegateModel.DelegationFrom;
                    ViewBag.DelegationTo          = objDelegateModel.DelegationTo;
                    objDelegateModel.DelegationId = 0;

                    DelegationMasterDTO objDelegationMasterDTO = new DelegationMasterDTO();

                    Common.Common.CopyObjectPropertyByName(objDelegateModel, objDelegationMasterDTO);

                    using (DelegationMasterSL objDelegationMasterSL = new DelegationMasterSL())
                    {
                        objDelegationMasterDTO = objDelegationMasterSL.SaveDetails(objDelegationMasterDTO, nPatrialSave, objLoginUserDetails.CompanyDBConnectionString, objLoginUserDetails.LoggedInUserID);
                        bStatusFlag            = true;
                        ErrorDictionary.Add("id", Convert.ToString(objDelegationMasterDTO.DelegationId));
                    }
                }
                else
                {
                    ErrorDictionary = GetModelStateErrorsAsString();
                }
            }catch (Exception e)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(e.InnerException.Data[0].ToString());
                ModelState.AddModelError("error", sErrMessage);
                ErrorDictionary = GetModelStateErrorsAsString();
            }
            finally
            {
                objLoginUserDetails = null;
            }

            return(Json(new
            {
                status = bStatusFlag,
                msg = ErrorDictionary,
                user_action = acid
            }));
        }
        public ActionResult Edit(user user)
        {
            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla")
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                        }
                        else
                        {
                            try
                            {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int    width    = int.Parse(ConfigurationManager.AppSettings["Image_User_Width"]);
                                    int    height   = int.Parse(ConfigurationManager.AppSettings["Image_User_Height"]);
                                    string name     = getGuid() + ".jpg";
                                    string filepath = string.Format("users/{0}", name);
                                    string address  = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    user.Image = address;
                                }
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError(keyname, "Upload error: " + ex.Message + " // " + ex.InnerException.Message);
                            }
                        }

                        ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name", user.CountryID);
                        ViewBag.Role      = new SelectList(db.user_roles, "RoleName", "RoleName", user.Role);
                        return(View(user));
                    }
                }
            }

            if (ModelState.IsValid)
            {
                //do not change the password!
                //user.UserPassword = computeHash(user.UserPassword.ToUpper());
                user.UserName = user.Email;
                if (string.IsNullOrEmpty(user.Image) || user.Image.Length <= 3)
                {
                    user.Image = "https://s3-eu-west-1.amazonaws.com/localactors-webapp/users/default_user_256.png";
                }

                db.users.Attach(user);
                db.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name", user.CountryID);
            ViewBag.Role      = new SelectList(db.user_roles, "RoleName", "RoleName", user.Role);
            return(View(user));
        }
        public ActionResult Create(user user)
        {
            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla")
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                        }
                        else
                        {
                            try
                            {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int    width    = int.Parse(ConfigurationManager.AppSettings["Image_User_Width"]);
                                    int    height   = int.Parse(ConfigurationManager.AppSettings["Image_User_Height"]);
                                    string name     = getGuid() + ".jpg";
                                    string filepath = string.Format("users/{0}", name);
                                    string address  = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    user.Image = address;
                                }
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError(keyname, "Upload error: " + ex.Message + " // " + ex.InnerException.Message);
                            }
                        }

                        ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name");
                        ViewBag.Role      = new SelectList(db.user_roles, "RoleName", "RoleName");
                        return(View(user));
                    }
                }
            }
            else
            {
                user.Image = "https://s3-eu-west-1.amazonaws.com/localactors-webapp/users/default_user_256.png";
            }


            if (ModelState.IsValid)
            {
                var usr = db.users.FirstOrDefault(x => x.Email.ToLower() == user.Email.ToLower());
                if (usr != null)
                {
                    ModelState.AddModelError("Email", "Indirizzo Email gia registrato");
                    return(View(user));
                }

                string key     = computeHash(DateTime.Now.ToString("dd/MM/yyHHmmss") + user.Email);
                user   newuser = new user
                {
                    UserPassword  = computeHash(user.UserPassword.ToUpper()),
                    UserName      = user.Email.ToLower(),
                    Name          = user.Name,
                    Lastname      = user.Lastname,
                    Bio           = user.Bio,
                    Image         = user.Image,
                    Email         = user.Email,
                    CountryID     = user.CountryID,
                    DateJoined    = DateTime.Now,
                    DateLastLogin = DateTime.Now,
                    Enabled       = true,
                    Confirmed     = false,
                    Reset         = false,
                    Privacy       = true,
                    Role          = user.Role,
                    Email_Hash    = key,
                    Newsletter    = user.Newsletter,

                    Contact_Blog     = user.Contact_Blog,
                    Contact_Email    = user.Contact_Email,
                    Contact_Facebook = user.Contact_Facebook,
                    Contact_Linkedin = user.Contact_Linkedin,
                    Contact_Skype    = user.Contact_Skype,
                    Contact_Tel      = user.Contact_Tel,
                    Contact_Twitter  = user.Contact_Twitter,
                    Contact_Web      = user.Contact_Web
                };

                db.users.AddObject(newuser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name");
            ViewBag.Role      = new SelectList(db.user_roles, "RoleName", "RoleName");
            return(View(user));
        }
Example #4
0
        public JsonResult DeleteSingleDocumentDetails(int?nDocumentDetailsID, int nIndex, int nSubIndex, string GUID, int acid, int nMapToTypeCodeId = 0, int nMapToId = 0, int nPurposeCodeId = 0)
        {
            bool             bReturn             = false;
            bool             statusFlag          = false;
            bool             userType            = false;
            var              ErrorDictionary     = new Dictionary <string, string>();
            bool             removeMapToId       = true;
            LoginUserDetails objLoginUserDetails = null;
            Dictionary <string, DocumentDetailsDTO> dicDocumentDetailsDTO = null;

            try
            {
                objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
                //  DocumentDetailsDTO objDocumentDetailsDTO = new DocumentDetailsDTO();
                string directory = ConfigurationManager.AppSettings["Document"];
                if (nDocumentDetailsID != null && nDocumentDetailsID != 0)
                {
                    if (nMapToTypeCodeId == ConstEnum.Code.UserDocument)
                    {
                        userType = true;
                    }
                    if (acid == InsiderTrading.Common.ConstEnum.UserActions.COMPANY_VIEW)
                    {
                        removeMapToId = false;
                    }
                    using (DocumentDetailsSL objDocumentDetailsSL = new DocumentDetailsSL())
                    {
                        bReturn = objDocumentDetailsSL.DeleteDocumentDetails(objLoginUserDetails.CompanyDBConnectionString, Convert.ToInt32(nDocumentDetailsID), objLoginUserDetails.LoggedInUserID, nMapToTypeCodeId, nMapToId, Convert.ToInt32(nPurposeCodeId));
                        if (bReturn)
                        {
                            if (nMapToTypeCodeId != Common.ConstEnum.Code.TradingPolicy)
                            {
                                if (System.IO.File.Exists(Path.Combine(directory, nMapToTypeCodeId.ToString(), nMapToId.ToString(), GUID)))
                                {
                                    FileInfo file = new FileInfo(Path.Combine(directory, nMapToTypeCodeId.ToString(), nMapToId.ToString(), GUID));
                                    file.Delete();
                                }
                            }
                            statusFlag = true;
                            ErrorDictionary.Add("Document", "Record deleted");
                        }
                    }
                }
                else
                {
                    dicDocumentDetailsDTO = objLoginUserDetails.DocumentDetails;
                    if (dicDocumentDetailsDTO != null && dicDocumentDetailsDTO.Count > 0 && dicDocumentDetailsDTO.ContainsKey(GUID))
                    {
                        if (System.IO.File.Exists(Path.Combine(directory, "temp", GUID)))
                        {
                            FileInfo file = new FileInfo(Path.Combine(directory, "temp", GUID));
                            file.Delete();
                        }
                        objLoginUserDetails.DocumentDetails.Remove(GUID);
                        Common.Common.SetSessionValue(ConstEnum.SessionValue.UserDetails, objLoginUserDetails);
                        statusFlag = true;
                        ErrorDictionary.Add("Document", "Record deleted");
                    }
                }
            }
            catch (Exception exp)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                ModelState.AddModelError("Document", sErrMessage);
            }
            finally
            {
                objLoginUserDetails   = null;
                dicDocumentDetailsDTO = null;
            }

            return(Json(new
            {
                status = statusFlag,
                Message = ErrorDictionary,
                Index = nIndex,
                SubIndex = nSubIndex,
                userType = userType,
                removeMapToId = removeMapToId
            }, "text/html"));
        }
        public ActionResult ContentEdit(update_content update_content, int ProjectID = 0)
        {
            //File Upload
            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla")
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                            return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID }));
                        }

                        try
                        {
                            if (ext == ".png" || ext == ".jpg" || ext == ".jpeg")
                            {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int    width    = int.Parse(ConfigurationManager.AppSettings["Image_Update_Width"]);
                                    int    height   = int.Parse(ConfigurationManager.AppSettings["Image_Update_Height"]);
                                    string name     = getTimestamp() + ".jpg";
                                    string filepath = string.Format("projects/{0}/update_{1}/{2}", ProjectID, update_content.UpdateID, name);
                                    string address  = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    update_content.Media = address;
                                    update_content.Url   = address;
                                }
                            }
                            else
                            {
                                //ok, making the new filename
                                string filepath = string.Format("projects/{0}/update_{1}/{2}", ProjectID, update_content.UpdateID, file.FileName);
                                var    request  = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                request.InputStream = file.InputStream;
                                AmazonS3Client.PutObject(request);
                                string address = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                ModelState.Remove(keyname);
                                ModelState.Add(keyname, new ModelState());
                                ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                update_content.Media = address;
                                update_content.Url   = address;
                            }
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError(keyname, "Upload error: " + ex.Message);
                            return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID }));
                        }
                    }
                }
            }

            if (update_content.Date == null)
            {
                update_content.Date = DateTime.Now;
            }
            update_content.DateCreated = DateTime.Now;
            update_content.UserID      = CurrentUser.UserID;

            if (ModelState.IsValid)
            {
                db.update_content.Attach(update_content);
                db.ObjectStateManager.ChangeObjectState(update_content, EntityState.Modified);
                db.SaveChanges();
                return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID }));
            }

            return(RedirectToAction("Edit", "Update", new { id = update_content.UpdateID }));
        }
Example #6
0
        public ActionResult Save(InsiderTrading.Models.NSEGroupDocumentMappingModel objNSEGroupDocumentModel, Dictionary <int, List <DocumentDetailsModel> > dicPolicyDocumentsUploadFileList, int GroupId)
        {
            ModelState.Remove("KEY");
            ModelState.Add("KEY", new ModelState());
            ModelState.Clear();
            var StockExchangeDateSubmission = Request.Form["SubmissionFromDate"];
            LoginUserDetails            objLoginUserDetails  = null;
            DocumentDetailsSL           objDocumentDetailsSL = new DocumentDetailsSL();
            List <DocumentDetailsModel> UploadFileDocumentDetailsModelList = null;
            NSEGroupDocumentMappingDTO  objNSEGroupDocDTO     = new NSEGroupDocumentMappingDTO();
            NSEGroupDetailsDTO          objNSEGroupDetailsDTO = new NSEGroupDetailsDTO();
            NSEGroupDTO objNSEGroupDTO = new NSEGroupDTO();

            objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
            DateTime?date = null;

            using (NSEGroupSL ObjNSEGroupSL = new NSEGroupSL())
            {
                List <NSEGroupDTO> lstDate = ObjNSEGroupSL.Get_Group_Date(objLoginUserDetails.CompanyDBConnectionString, GroupId);
                foreach (var submitdate in lstDate)
                {
                    date = submitdate.DownloadedDate;
                }
            }
            if (StockExchangeDateSubmission == "")
            {
                ModelState.AddModelError("DateOfSubmissionToNSE", Common.Common.getResource("nse_lbl_50535"));
            }
            else
            {
                objNSEGroupDTO.SubmissionDate = Convert.ToDateTime(StockExchangeDateSubmission);
                if (objNSEGroupDTO.SubmissionDate > Common.Common.GetCurrentDate(objLoginUserDetails.CompanyDBConnectionString))
                {
                    ModelState.AddModelError("DateOfSubmissionToNSE", Common.Common.getResource("nse_lbl_50534"));
                }
                if (Convert.ToDateTime(date).Date > objNSEGroupDTO.SubmissionDate)
                {
                    ModelState.AddModelError("DateOfSubmissionToNSE", Common.Common.getResource("nse_lbl_50536"));
                }
            }
            if (ModelState.IsValid)
            {
                if (dicPolicyDocumentsUploadFileList.Count > 0) // file is uploaded and data found for file upload
                {
                    UploadFileDocumentDetailsModelList = dicPolicyDocumentsUploadFileList[ConstEnum.Code.UploadNseDocument];
                }
                List <DocumentDetailsModel> objSavedDocumentDetialsModelList = objDocumentDetailsSL.SaveDocumentDetails(objLoginUserDetails.CompanyDBConnectionString, UploadFileDocumentDetailsModelList, ConstEnum.Code.UploadNseDocument, GroupId, objLoginUserDetails.LoggedInUserID, objLoginUserDetails.CompanyName);
                DocumentDetailsDTO          objDocumentDetailsDTO            = null;
                objDocumentDetailsDTO = new DocumentDetailsDTO();
                using (NSEGroupSL objNSEGroupSL = new NSEGroupSL())
                {
                    if (UploadFileDocumentDetailsModelList != null)
                    {
                        foreach (var fleGUID in UploadFileDocumentDetailsModelList)
                        {
                            objNSEGroupDetailsDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                            objNSEGroupDetailsDTO.GroupId        = GroupId;
                            List <NSEGroupDetailsDTO> GrouplistDetails = objNSEGroupSL.Save_NSEGroup_Details(objLoginUserDetails.CompanyDBConnectionString, objNSEGroupDetailsDTO);
                            foreach (var nseuserId in GrouplistDetails)
                            {
                                objNSEGroupDocDTO.NSEGroupDetailsId = nseuserId.NSEGroupDetailsId;
                                objNSEGroupDetailsDTO.GroupId       = Convert.ToInt32(GroupId);
                                bool bReturnDoc = objNSEGroupSL.Save_New_NSEDocument(objLoginUserDetails.CompanyDBConnectionString, objNSEGroupDocDTO, fleGUID.GUID);
                            }
                        }
                    }
                    objNSEGroupDTO.GroupId        = GroupId;
                    objNSEGroupDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                    objNSEGroupDTO.StatusCodeId   = 508007;
                    bool bReturn = objNSEGroupSL.Update_NSEGroup(objLoginUserDetails.CompanyDBConnectionString, objNSEGroupDTO);
                }
                TradingTransactionMasterDTO objTradingTransactionMasterDTO = null;
                using (TradingTransactionSL objTradingTransactionSL = new TradingTransactionSL())
                {
                    using (NSEGroupSL objNSEGroupSL = new NSEGroupSL())
                    {
                        List <NSEGroupDetailsDTO> grpTransIdList = objNSEGroupSL.Get_Group_TransactionId(objLoginUserDetails.CompanyDBConnectionString, GroupId);
                        foreach (var TransId in grpTransIdList)
                        {
                            objTradingTransactionMasterDTO = new TradingTransactionMasterDTO();
                            objTradingTransactionMasterDTO.TransactionMasterId        = TransId.transId;
                            objTradingTransactionMasterDTO.TransactionStatusCodeId    = ConstEnum.Code.DisclosureStatusForHardCopySubmittedByCO;
                            objTradingTransactionMasterDTO.HardCopyByCOSubmissionDate = Convert.ToDateTime(StockExchangeDateSubmission);
                            objTradingTransactionMasterDTO = objTradingTransactionSL.GetTradingTransactionMasterCreate(objLoginUserDetails.CompanyDBConnectionString, objTradingTransactionMasterDTO, objLoginUserDetails.LoggedInUserID, out nDisclosureCompletedFlag);
                        }
                    }
                }
                return(RedirectToAction("Index", "NSEDownload", new { acid = ConstEnum.UserActions.NSEDownload }));
            }
            else
            {
                ViewBag.groupId      = GroupId;
                ViewBag.DownloadDate = date;
                ViewBag.UserAction   = Common.ConstEnum.UserActions.NSEDownload;
                objNSEGroupDocumentModel.NSEGroupDocumentFile = Common.Common.GenerateDocumentList(ConstEnum.Code.UploadNseDocument, 0, 0, null, 0, false, 0, ConstEnum.FileUploadControlCount.NSEUploadFile);
                return(View("NSEUploadDoc", objNSEGroupDocumentModel));
            }
        }
        public ActionResult Create(UserInfoModel objUserInfoModel, string OldPassword)
        {
            int              nUserInfoID         = 0;
            string           Password            = null;
            UserInfoSL       objUserInfoSL       = new UserInfoSL();
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
            UserInfoDTO      objUserInfoDTO      = new UserInfoDTO();

            try
            {
                InsiderTrading.Common.Common.CopyObjectPropertyByName(objUserInfoModel, objUserInfoDTO);
                objUserInfoDTO.UserTypeCodeId = ConstEnum.Code.EmployeeType;
                objUserInfoDTO.IsInsider      = ConstEnum.UserType.Insider;
                objUserInfoDTO.StatusCodeId   = Common.Common.ConvertToInt32(ConstEnum.UserStatus.Active);
                objUserInfoDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                Common.Common.encryptData(objUserInfoModel.Password, out Password);
                if (!Password.Equals(OldPassword))
                {
                    objUserInfoDTO.Password = Password;
                }
                else
                {
                    objUserInfoDTO.Password = OldPassword;
                }
                if (objUserInfoDTO.StateId == 0)
                {
                    objUserInfoDTO.StateId = null;
                }
                if (objUserInfoDTO.CountryId == 0)
                {
                    objUserInfoDTO.CountryId = null;
                }
                if (objUserInfoDTO.Category == 0)
                {
                    objUserInfoDTO.Category = null;
                }
                if (objUserInfoDTO.SubCategory == 0)
                {
                    objUserInfoDTO.SubCategory = null;
                }
                if (objUserInfoDTO.GradeId == 0)
                {
                    objUserInfoDTO.GradeId = null;
                }
                if (objUserInfoDTO.DesignationId == 0)
                {
                    objUserInfoDTO.DesignationId = null;
                }
                if (objUserInfoDTO.DepartmentId == 0)
                {
                    objUserInfoDTO.DepartmentId = null;
                }
                objUserInfoDTO = objUserInfoSL.InsertUpdateUserDetails(objLoginUserDetails.CompanyDBConnectionString, objUserInfoDTO);
                if (objUserInfoDTO.UserInfoId != 0)
                {
                    nUserInfoID = objUserInfoDTO.UserInfoId;
                }
            }
            catch (Exception exp)
            {
                PopulateCombo();
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                ModelState.AddModelError("Error", sErrMessage);
                return(View("Create", objUserInfoModel));
            }
            finally
            {
                objUserInfoSL       = null;
                objLoginUserDetails = null;
                objUserInfoDTO      = null;
            }
            return(RedirectToAction("Create", new { nUserInfoID = nUserInfoID }));
        }
Example #8
0
        public ActionResult Create(project_photo project_photo, int projectid = 0, int returntoproject = 0)
        {
            var project = db.projects.FirstOrDefault(x => x.ProjectID == project_photo.ProjectID && x.UserID == CurrentUser.UserID);

            if (project == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            //File Upload
            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif")
                        {
                            try {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int    width    = int.Parse(ConfigurationManager.AppSettings["Image_Gallery_Width"]);
                                    int    height   = int.Parse(ConfigurationManager.AppSettings["Image_Gallery_Height"]);
                                    string name     = getTimestamp() + ".jpg";
                                    string filepath = string.Format("projects/{0}/photos/{1}", project_photo.ProjectID, name);
                                    string address  = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    project_photo.Url = address;
                                }
                            }
                            catch (Exception ex) {
                                ModelState.AddModelError(keyname, "Upload error: " + ex.Message);
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                        }
                    }
                }
            }

            if (ModelState.IsValid)
            {
                project_photo.ProjectID = project.ProjectID;
                db.project_photo.AddObject(project_photo);
                db.SaveChanges();

                if (returntoproject > 0)
                {
                    return(RedirectToAction("Edit", "Projects", new { id = project_photo.ProjectID }, "photos"));
                }

                return(RedirectToAction("Index", "ProjectPhotos", new { Area = "Publisher", projectid = project.ProjectID }));
            }

            ViewBag.returntoproject = returntoproject;
            ViewBag.Project         = db.projects.FirstOrDefault(x => x.ProjectID == project_photo.ProjectID);
            return(View(project_photo));
        }
Example #9
0
        public ActionResult Config(FormCollection form)
        {
            int updated = 0;
            int errors  = 0;

            foreach (string configKey in form.Keys)
            {
                Config config = _configRepository.First(item => item.Name.Equals(configKey));
                if (config != null)
                {
                    string     value      = Request.Form[configKey];
                    ModelState modelState = new ModelState();
                    modelState.Value = new ValueProviderResult(value, value, CultureInfo.CurrentUICulture);
                    if (value != config.Value)
                    {
                        if (string.IsNullOrEmpty(value))
                        {
                            ModelState.AddModelError(configKey, configKey + " requires a value");
                        }
                        else
                        {
                            var validation = ValidateConfig(config, value);
                            if (!validation.Valid)
                            {
                                modelState.Errors.Add(validation.FieldError);
                                ModelState.AddModelError(string.Empty, validation.Error);
                                errors++;
                            }
                            else
                            {
                                if (config.Name == "BoardTheme")
                                {
                                    _themeServices.ChangeDefaultTheme(int.Parse(value));
                                }
                                else
                                {
                                    config.Value = value;
                                    _configRepository.Update(config);
                                }
                                updated++;
                            }
                        }
                    }
                    ModelState.Add(configKey, modelState);
                }
            }

            if (updated != 0)
            {
                SetSuccess(updated + " configs updated");
            }

            if (errors != 0)
            {
                SetError(errors + " config errors. See the messages below");
            }

            SiteConfig.UpdateCache();
            Misc.ParseBBCodeScriptFile(_currentTheme);
            PersistModelState();
            return(RedirectToSelf());
        }
        public ActionResult Settings(user model)
        {
            user user = db.users.FirstOrDefault(x => x.UserName == User.Identity.Name);
            if (user == null)
                return RedirectToAction("Index", "Home");

            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {

                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla")
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                        }
                        else
                        {

                            try
                            {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int width = int.Parse(ConfigurationManager.AppSettings["Image_User_Width"]);
                                    int height = int.Parse(ConfigurationManager.AppSettings["Image_User_Height"]);
                                    string name = getGuid() + ".jpg";
                                    string filepath = string.Format("users/{0}", name);
                                    string address = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    user.Image = address;
                                }
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError(keyname, "Upload error: " + ex.Message);
                            }
                        }

                        ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name", user.CountryID);
                        return View(user);
                    }
                }
            }

            if (ModelState.IsValid) {
                user.Name = model.Name;
                user.Lastname = model.Lastname;
                user.Bio = model.Bio;
                user.Image = model.Image;
                user.CountryID = model.CountryID;

                user.Contact_Blog = model.Contact_Blog;
                user.Contact_Email = model.Contact_Email;
                user.Contact_Facebook = model.Contact_Facebook;
                user.Contact_Linkedin = model.Contact_Linkedin;
                user.Contact_Skype = model.Contact_Skype;
                user.Contact_Tel = model.Contact_Tel;
                user.Contact_Twitter = model.Contact_Twitter;
                user.Contact_Web = model.Contact_Web;

                db.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);
                db.SaveChanges();

                //clear
                OutputCacheAttribute.ChildActionCache = new MemoryCache("newcache");
            }

            ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name", user.CountryID);
            return View(user);
        }
Example #11
0
        public ActionResult CommentCreate(update_comment model)
        {
            update  update  = db.updates.Include("project").FirstOrDefault(x => x.UpdateID == model.UpdateID);
            project project = update.project;


            model.UserID  = CurrentUser.UserID;
            model.Date    = DateTime.Now;
            model.Picture = null;

            ModelState.Remove("UserID");
            ModelState.Add("UserID", new ModelState());
            ModelState.SetModelValue("UserID", new ValueProviderResult(CurrentUser.UserID, CurrentUser.UserID.ToString(), null));

            ModelState.Remove("Date");
            ModelState.Add("Date", new ModelState());
            ModelState.SetModelValue("Date", new ValueProviderResult(DateTime.Now, DateTime.Now.ToString(), null));


            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla")
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                        }
                        else
                        {
                            try
                            {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int    width    = int.Parse(ConfigurationManager.AppSettings["Image_Comment_Width"]);
                                    int    height   = int.Parse(ConfigurationManager.AppSettings["Image_Comment_Height"]);
                                    string name     = getTimestamp() + ".jpg";
                                    string filepath = string.Format("projects/{0}/update/{1}/comments/{2}", update.ProjectID, update.UpdateID, file.FileName);
                                    string address  = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    model.Picture = address;
                                }
                            }
                            catch (Exception ex)
                            {
                                ModelState.AddModelError(keyname, "Upload error: " + ex.Message);
                            }
                        }
                    }
                }
            }

            if (ModelState.IsValid)
            {
                //akismet
                Validator validator = new Validator(ConfigurationManager.AppSettings["Akismet_Key"]);
                bool      isspam    = validator.IsSpam(new Comment()
                {
                    comment_author_email = CurrentUser.Email,
                    blog            = ConfigurationManager.AppSettings["Akismet_Url"],
                    comment_author  = CurrentUser.UserName,
                    comment_content = model.Text,
                    user_agent      = Request.UserAgent,
                    user_ip         = Request.UserHostAddress,
                    referrer        = Request.UrlReferrer != null ? Request.UrlReferrer.AbsoluteUri : "",
                    comment_type    = "comment"
                });

                if (isspam)
                {
                    string spam = string.Format("From: {0}\r\nProject: {1}\r\nProjectID: {2}\r\n\r\nComment SPAM TEXT: {3}\r\n\r\nThis post was not saved.", CurrentUser.Email, project.Title, update.ProjectID, model.Text);
                    //SendMailAwsAdmin("New Comment SPAM: " + project.Title, spam);
                    LogStuff("SPAM", DateTime.Now, spam);
                }
                else
                {
                    update.update_comment.Add(model);
                    db.SaveChanges();

                    string body = string.Format("From: {0}\r\nProject: {1}\r\nProjectID: {2}\r\n\r\nComment: {3}", CurrentUser.Email, project.Title, update.ProjectID, model.Text);
                    SendMailAws(project.user.Email, "New Comment : " + project.Title, body);
                    SendMailAwsAdmin("New Comment : " + project.Title, body);
                }
            }

            if (Request.UrlReferrer != null)
            {
                HttpResponse.RemoveOutputCacheItem(Request.UrlReferrer.AbsolutePath);
                return(Redirect(ReferrerUrlTimestamped() + "#comments-" + model.update.UpdateID));
            }
            return(Redirect("/"));
        }
        public JsonResult Delete(int acid, int TemplateMasterId)
        {
            bool             statusFlag          = false;
            var              ErrorDictionary     = new Dictionary <string, string>();
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);

            Common.Common objCommon = new Common.Common();
            try
            {
                // TemplateMasterSL objTemplateMasterSL = new TemplateMasterSL();
                //TemplateMasterModel objTemplateMasterModel = new TemplateMasterModel();
                if (!objCommon.ValidateCSRFForAJAX())
                {
                    return(Json(new
                    {
                        status = statusFlag,
                        Message = ErrorDictionary
                    }, JsonRequestBehavior.AllowGet));
                }
                using (var objTemplateMasterSL = new TemplateMasterSL())
                {
                    bool result = objTemplateMasterSL.Delete(objLoginUserDetails.CompanyDBConnectionString, TemplateMasterId, objLoginUserDetails.LoggedInUserID);
                }
                // return RedirectToAction("Index", "TemplateMaster",new {acid = ConstEnum.UserActions.TEMPLATE_LIST_RIGHT });
                statusFlag = true;
                ErrorDictionary.Add("success", Common.Common.getResource("tra_msg_16175"));
            }
            catch (Exception exp)
            {
                //string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                //ModelState.AddModelError("Error", sErrMessage);
                TemplateMasterModel     objTemplateMasterModel = new TemplateMasterModel();
                List <PopulateComboDTO> lstList = new List <PopulateComboDTO>();

                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.RoleStatus, null, null, null, null, true);
                ViewBag.TemplateStatus = lstList;

                //get list of communication mode
                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.CommunicationModes, null, null, null, null, true);
                ViewBag.CommunicationMode = lstList;

                //get list of disclousre type
                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.DisclosureType, null, null, null, null, true);
                ViewBag.DisclosureType = lstList;

                lstList = null;
                FillGrid(ConstEnum.GridType.TemplateMasteList, null, null, null);

                // return View("View", objTemplateMasterModel);
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                ModelState.AddModelError("error", sErrMessage);
                ErrorDictionary = GetModelStateErrorsAsString();
            }
            finally
            {
                objLoginUserDetails = null;
            }
            return(Json(new
            {
                status = statusFlag,
                Message = ErrorDictionary
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SaveAction(int acid, TemplateMasterModel objTemplateMasterModel, string calledFrom)
        {
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);

            try
            {
                // TODO: Add insert logic here
                objTemplateMasterModel.Contents     = HttpUtility.HtmlEncode(objTemplateMasterModel.Contents);
                objTemplateMasterModel.Subject      = HttpUtility.HtmlEncode(objTemplateMasterModel.Subject);
                objTemplateMasterModel.TemplateName = HttpUtility.HtmlEncode(objTemplateMasterModel.TemplateName);
                objTemplateMasterModel.Signature    = HttpUtility.HtmlEncode(objTemplateMasterModel.Signature);

                string editorContent = Common.HtmlUtil.SanitizeHtml(objTemplateMasterModel.Contents);
                if (objTemplateMasterModel.CommunicationModeCodeId != Common.ConstEnum.Code.CommunicationModeForSMS && objTemplateMasterModel.CommunicationModeCodeId != Common.ConstEnum.Code.CommunicationModeForTextAlert)
                {
                    objTemplateMasterModel.Contents = editorContent.Replace(Environment.NewLine, "\\r\\n");
                    //objTemplateMasterModel.Contents = HttpUtility.HtmlEncode(editorContent);
                }

                if (objTemplateMasterModel.CommunicationModeCodeId == Common.ConstEnum.Code.CommunicationModeForFormE)
                {
                    objTemplateMasterModel.Contents = editorContent.Replace("[[", "[");
                    objTemplateMasterModel.Contents = editorContent.Replace("]]", "]");
                    //  objTemplateMasterModel.Contents = HttpUtility.HtmlEncode(editorContent);
                }

                if (objTemplateMasterModel.CommunicationModeCodeId == Common.ConstEnum.Code.CommunicationModeForEmail)
                {
                    objTemplateMasterModel.Contents = editorContent.Replace("[[|~|", "|~|");
                    objTemplateMasterModel.Contents = editorContent.Replace("|~|]]", "|~|");
                    // objTemplateMasterModel.Contents = HttpUtility.HtmlEncode(editorContent);
                }

                if (objTemplateMasterModel.Signature != null)
                {
                    objTemplateMasterModel.Signature = objTemplateMasterModel.Signature.Replace(Environment.NewLine, "\\r\\n");
                }

                if (objTemplateMasterModel.ToAddress1 != null)
                {
                    objTemplateMasterModel.ToAddress1 = objTemplateMasterModel.ToAddress1.Replace(Environment.NewLine, "\\r\\n");
                    objTemplateMasterModel.ToAddress1 = HttpUtility.HtmlEncode(objTemplateMasterModel.ToAddress1);
                }
                if (objTemplateMasterModel.CommunicationModeCodeId == Common.ConstEnum.Code.CommunicationModeForEmail && objTemplateMasterModel.CommunicationFrom != objTemplateMasterModel.CommunicationFromEmail)
                {
                    objTemplateMasterModel.CommunicationFrom = objTemplateMasterModel.CommunicationFromEmail;
                }
                //for communcition type letter -- check if checkbox address 2 optional is checked or not
                // if checkbox is NOT checked then set null else replace new line character for text entered
                if (objTemplateMasterModel.CommunicationModeCodeId == ConstEnum.Code.CommunicationModeForLetter && !objTemplateMasterModel.IsCommunicationTemplate)
                {
                    objTemplateMasterModel.ToAddress2 = null;
                }
                else
                {
                    if (objTemplateMasterModel.ToAddress2 != null)
                    {
                        objTemplateMasterModel.ToAddress2 = objTemplateMasterModel.ToAddress2.Replace(Environment.NewLine, "\\r\\n");
                        objTemplateMasterModel.ToAddress2 = HttpUtility.HtmlEncode(objTemplateMasterModel.ToAddress2);
                    }
                }

                // TemplateMasterSL objTemplateMasterSL = new TemplateMasterSL();
                TemplateMasterDTO objTemplateMasterDTO = new TemplateMasterDTO();

                InsiderTrading.Common.Common.CopyObjectPropertyByName(objTemplateMasterModel, objTemplateMasterDTO);
                using (var objTemplateMasterSL = new TemplateMasterSL())
                {
                    objTemplateMasterDTO = objTemplateMasterSL.SaveDetails(objTemplateMasterDTO, objLoginUserDetails.CompanyDBConnectionString, objLoginUserDetails.LoggedInUserID);
                }
                if (calledFrom == "Communication")
                {
                    HttpUtility.HtmlDecode(objTemplateMasterDTO.TemplateName, objTemplateWriter);
                    //return RedirectToAction("Create", new { TemplateMasterId = objTemplateMasterDTO.TemplateMasterId, calledFrom = calledFrom });
                    return(Json(new
                    {
                        status = true,
                        Message = Common.Common.getResource("tra_msg_16153"),//Common.Common.getResource("rul_msg_15380")//
                        CommunicationModeCodeId = objTemplateMasterDTO.CommunicationModeCodeId,
                        TemplateName = Convert.ToString(objTemplateWriter),
                        TemplateMasterId = objTemplateMasterDTO.TemplateMasterId
                    }, JsonRequestBehavior.AllowGet));
                }
                else if (calledFrom == "CommunicationRule")
                { //CommunicationRuleMaster/Index?acid=179
                    return(Json(new
                    {
                        status = true,
                        Message = Common.Common.getResource("tra_msg_16153"),
                        CommunicationModeCodeId = objTemplateMasterDTO.CommunicationModeCodeId,
                        TemplateName = objTemplateMasterDTO.TemplateName,
                        TemplateMasterId = objTemplateMasterDTO.TemplateMasterId,
                        IsActive = objTemplateMasterDTO.IsActive
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(RedirectToAction("Index", "TemplateMaster", new { acid = ConstEnum.UserActions.TEMPLATE_LIST_RIGHT }).Success(Common.Common.getResource("tra_msg_16153")));
                }
            }
            catch (Exception exp)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                //return View();
                //return Json(new
                //{
                //    status = false,
                //    Message = sErrMessage
                //}, JsonRequestBehavior.AllowGet);
                ModelState.AddModelError("Error", sErrMessage);
                if (calledFrom == "Communication")
                {
                    return(Json(new
                    {
                        status = false,
                        error = ModelState.ToSerializedDictionary(),
                        Message = sErrMessage
                    }));
                }
                else if (calledFrom == "CommunicationRule")
                { //CommunicationRuleMaster/Index?acid=179
                    return(Json(new
                    {
                        status = false,
                        error = ModelState.ToSerializedDictionary(),
                        Message = sErrMessage
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    List <PopulateComboDTO> lstList = new List <PopulateComboDTO>();

                    //get list of communication mode
                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.CommunicationModes, null, null, null, null, true);
                    ViewBag.CommunicationMode = lstList;

                    //get list of disclousre type
                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.DisclosureType, null, null, null, null, true);
                    ViewBag.DisclosureType = lstList;

                    //get list of user type for letter type communicaiton mode
                    lstList           = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.DisclosureLetterForUserType, ConstEnum.Code.CommunicationModeForLetter.ToString(), null, null, null, true);
                    ViewBag.LetterFor = lstList;

                    //get list of user type for FAQ type communicaiton mode
                    lstList        = FillComboValues(ConstEnum.ComboType.ListOfCode, ConstEnum.CodeGroup.DisclosureLetterForUserType, ConstEnum.Code.CommunicationModeForFAQ.ToString(), null, null, null, true);
                    ViewBag.FAQFor = lstList;

                    ViewBag.TemplateMasterId     = objTemplateMasterModel.TemplateMasterId;
                    ViewBag.CommunicationMode_id = objTemplateMasterModel.CommunicationModeCodeId;
                    ViewBag.IsDisplayBackButton  = true;
                    ViewBag.calledFrom           = calledFrom;

                    objTemplateMasterModel.Contents = objTemplateMasterModel.Contents.Replace("\\r\\n", Environment.NewLine);
                    HttpUtility.HtmlDecode(objTemplateMasterModel.Contents, objContentsWriter);
                    objTemplateMasterModel.Contents = objContentsWriter.ToString();

                    HttpUtility.HtmlDecode(objTemplateMasterModel.Subject, objSubjectWriter);
                    objTemplateMasterModel.Subject = objSubjectWriter.ToString();


                    HttpUtility.HtmlDecode(objTemplateMasterModel.TemplateName, objTemplateWriter);
                    objTemplateMasterModel.TemplateName = objTemplateWriter.ToString();

                    if (objTemplateMasterModel.Signature != null)
                    {
                        objTemplateMasterModel.Signature = objTemplateMasterModel.Signature.Replace("\\r\\n", Environment.NewLine);
                        HttpUtility.HtmlDecode(objTemplateMasterModel.Signature, objSignatureWriter);
                        objTemplateMasterModel.Signature = objSignatureWriter.ToString();
                    }

                    if (objTemplateMasterModel.ToAddress1 != null)
                    {
                        objTemplateMasterModel.ToAddress1 = objTemplateMasterModel.ToAddress1.Replace("\\r\\n", Environment.NewLine);
                        HttpUtility.HtmlDecode(objTemplateMasterModel.ToAddress1, objAddress1Writer);
                        objTemplateMasterModel.ToAddress1 = objAddress1Writer.ToString();
                    }

                    //for communcition type letter -- check if checkbox address 2 optional is checked or not
                    // if checkbox is NOT checked then set null else replace new line character for text entered
                    if (objTemplateMasterModel.CommunicationModeCodeId == ConstEnum.Code.CommunicationModeForLetter && !objTemplateMasterModel.IsCommunicationTemplate)
                    {
                        objTemplateMasterModel.ToAddress2 = null;
                    }
                    else
                    {
                        if (objTemplateMasterModel.ToAddress2 != null)
                        {
                            objTemplateMasterModel.ToAddress2 = objTemplateMasterModel.ToAddress2.Replace("\\r\\n", Environment.NewLine);
                            HttpUtility.HtmlDecode(objTemplateMasterModel.ToAddress2, objAddress2Writer);
                            objTemplateMasterModel.ToAddress2 = objAddress2Writer.ToString();
                        }
                    }
                    lstList = null;

                    ViewBag.acid = acid;

                    return(View("Create", objTemplateMasterModel));
                }
            }
            finally
            {
                objLoginUserDetails    = null;
                objTemplateMasterModel = null;
            }
        }
Example #14
0
        public JsonResult SaveCommunicationRule(int acid, CommunicationRuleMasterModel objCommunicationRuleMasterModel)
        {
            bool             bReturn             = true;
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);

            Common.Common objCommon = new Common.Common();
            try
            {
                if (!objCommon.ValidateCSRFForAJAX())
                {
                    Json(new { status = false, error = ModelState.ToSerializedDictionary() });
                }
                // TODO: Add insert logic here
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                // CommunicationRuleMasterSL objCommunicationRuleMasterSL = new CommunicationRuleMasterSL();
                CommunicationRuleMasterDTO objCommunicationRuleMasterDTO = new CommunicationRuleMasterDTO();
                InsiderTrading.Common.Common.CopyObjectPropertyByName(objCommunicationRuleMasterModel, objCommunicationRuleMasterDTO);
                if (objCommunicationRuleMasterModel.SelectTriggerEventCodeId != null && objCommunicationRuleMasterModel.SelectTriggerEventCodeId.Count() > 0)
                {
                    var sSubmittedSecurityTypeList = String.Join(",", objCommunicationRuleMasterModel.SelectTriggerEventCodeId);
                    objCommunicationRuleMasterDTO.TriggerEventCodeId = sSubmittedSecurityTypeList;
                }
                if (objCommunicationRuleMasterModel.SelectOffsetEventCodeId != null && objCommunicationRuleMasterModel.SelectOffsetEventCodeId.Count() > 0)
                {
                    var sSubmittedSecurityTypeList = String.Join(",", objCommunicationRuleMasterModel.SelectOffsetEventCodeId);
                    objCommunicationRuleMasterDTO.OffsetEventCodeId = sSubmittedSecurityTypeList;
                }
                if (objCommunicationRuleMasterModel.RuleCategoryCodeId == ConstEnum.Code.CommunicationRuleCategoryAuto && ((objCommunicationRuleMasterDTO.TriggerEventCodeId == null || objCommunicationRuleMasterDTO.TriggerEventCodeId == "") && (objCommunicationRuleMasterDTO.OffsetEventCodeId == null || objCommunicationRuleMasterDTO.OffsetEventCodeId == "")))
                {
                    ModelState.AddModelError("TriggerEventCodeId", InsiderTrading.Common.Common.getResource("cmu_msg_18062"));
                    bReturn = false;
                }
                objCommunicationRuleMasterDTO.RuleForCodeId = "";
                if (objCommunicationRuleMasterModel.RuleForCodeId_bool != null)
                {
                    objCommunicationRuleMasterDTO.RuleForCodeId = (objCommunicationRuleMasterModel.RuleForCodeId_bool == YesNo.Yes) ? Convert.ToString(ConstEnum.Code.CommunicationRuleForUserTypeCO) : Convert.ToString(ConstEnum.Code.CommunicationRuleForUserTypeInsider);
                }
                if (objCommunicationRuleMasterModel.EventsApplyToCodeId_bool != null)
                {
                    objCommunicationRuleMasterDTO.EventsApplyToCodeId = (objCommunicationRuleMasterModel.EventsApplyToCodeId_bool == YesNo.Yes) ? ConstEnum.Code.CommunicationRuleEventsToApplyUserTypeCO : ConstEnum.Code.CommunicationRuleEventsToApplyUserTypeInsider;
                }
                if (objCommunicationRuleMasterModel.InsiderPersonalize != null)
                {
                    objCommunicationRuleMasterDTO.InsiderPersonalizeFlag = (objCommunicationRuleMasterModel.InsiderPersonalize == YesNo.Yes) ? true : false;
                }
                #region
                DataTable tblCommunicationRuleModeMasterType = new DataTable("CommunicationRuleModeMasterType");
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("RuleModeId", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("RuleId", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("ModeCodeId", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("TemplateId", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("WaitDaysAfterTriggerEvent", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("ExecFrequencyCodeId", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("NotificationLimit", typeof(int)));
                tblCommunicationRuleModeMasterType.Columns.Add(new DataColumn("UserId", typeof(int)));

                foreach (CommunicationRuleModeMasterModel CommunicationRuleModeMasterMode in objCommunicationRuleMasterModel.CommunicationRuleModeMasterModelList)
                {
                    DataRow row = tblCommunicationRuleModeMasterType.NewRow();
                    if (CommunicationRuleModeMasterMode.RuleModeId != null)
                    {
                        row["RuleModeId"] = CommunicationRuleModeMasterMode.RuleModeId;
                    }
                    else
                    {
                        row["RuleModeId"] = 0;
                    }

                    row["RuleId"] = objCommunicationRuleMasterModel.RuleId;

                    if (CommunicationRuleModeMasterMode.UserId != null)
                    {
                        row["UserId"] = CommunicationRuleModeMasterMode.UserId;
                    }
                    if (CommunicationRuleModeMasterMode.ModeCodeId != null && CommunicationRuleModeMasterMode.ModeCodeId != 0)
                    {
                        row["ModeCodeId"] = CommunicationRuleModeMasterMode.ModeCodeId;
                    }
                    else
                    {
                        ModelState.AddModelError("ModeCodeId", InsiderTrading.Common.Common.getResource("cmu_msg_18051"));
                        bReturn = false;
                    }
                    if (CommunicationRuleModeMasterMode.TemplateId != null && CommunicationRuleModeMasterMode.TemplateId != 0)
                    {
                        row["TemplateId"] = CommunicationRuleModeMasterMode.TemplateId;
                    }
                    else
                    {
                        ModelState.AddModelError("TemplateId", InsiderTrading.Common.Common.getResource("cmu_msg_18052"));
                        bReturn = false;
                    }
                    if (CommunicationRuleModeMasterMode.WaitDaysAfterTriggerEvent != null)
                    {
                        row["WaitDaysAfterTriggerEvent"] = CommunicationRuleModeMasterMode.WaitDaysAfterTriggerEvent;
                    }
                    else
                    {
                        ModelState.AddModelError("WaitDaysAfterTriggerEvent", InsiderTrading.Common.Common.getResource("cmu_msg_18053"));
                        bReturn = false;
                    }
                    if (CommunicationRuleModeMasterMode.ExecFrequencyCodeId != null && CommunicationRuleModeMasterMode.ExecFrequencyCodeId != 0)
                    {
                        row["ExecFrequencyCodeId"] = CommunicationRuleModeMasterMode.ExecFrequencyCodeId;
                    }
                    else
                    {
                        ModelState.AddModelError("ExecFrequencyCodeId", InsiderTrading.Common.Common.getResource("cmu_msg_18054"));
                        bReturn = false;
                    }
                    if (CommunicationRuleModeMasterMode.NotificationLimit != null)
                    {
                        row["NotificationLimit"] = CommunicationRuleModeMasterMode.NotificationLimit;
                    }
                    else
                    {
                        ModelState.AddModelError("NotificationLimit", InsiderTrading.Common.Common.getResource("cmu_msg_18055"));
                        bReturn = false;
                    }
                    if (!bReturn)
                    {
                        break;
                    }
                    tblCommunicationRuleModeMasterType.Rows.Add(row);
                }
                //check policy document windows status and by default set windows status to incomplete
                if (objCommunicationRuleMasterModel.RuleStatus != null)
                {
                    switch (objCommunicationRuleMasterModel.RuleStatus)
                    {
                    case InsiderTrading.Models.CommunicationRuleMasterModel.RuleStatusCode.Inactive:
                        objCommunicationRuleMasterDTO.RuleStatusCodeId = ConstEnum.Code.CommunicationRuleStatusInactive;
                        break;

                    case InsiderTrading.Models.CommunicationRuleMasterModel.RuleStatusCode.Active:
                        objCommunicationRuleMasterDTO.RuleStatusCodeId = ConstEnum.Code.CommunicationRuleStatusActive;
                        break;

                    default:
                        objCommunicationRuleMasterDTO.RuleStatusCodeId = ConstEnum.Code.CommunicationRuleStatusInactive;
                        break;
                    }
                }
                else
                {
                    objCommunicationRuleMasterDTO.RuleStatusCodeId = ConstEnum.Code.CommunicationRuleStatusInactive;
                }
                #endregion
                if (!bReturn && !ModelState.IsValid)
                {
                    #region Show error
                    List <PopulateComboDTO> lstList = new List <PopulateComboDTO>();

                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationRuleCategory).ToString(), null, null, null, null, true);
                    ViewBag.RuleCategoryCodeList = lstList;

                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.Events).ToString(), null, null, null, null, false);
                    ViewBag.TriggerEventCodeList = lstList;

                    lstList = FillComboValues(ConstEnum.ComboType.ListofEventsWithUserTypeForCommunicatioTriggerEvent, null, null, null, null, null, false);
                    ViewBag.TriggerEventCodeWithUserTypeList = lstList;

                    objCommunicationRuleMasterModel.AssignedTriggerEventCodeId = new List <PopulateComboDTO>();
                    objCommunicationRuleMasterModel.AssignedOffsetEventCodeId  = new List <PopulateComboDTO>();

                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.Events).ToString(), null, null, null, null, false);
                    ViewBag.OffsetEventCodeList = lstList;

                    //lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationRuleStatus).ToString(), null, null, null, null, false);
                    //ViewBag.RuleStatusCodeId = lstList;

                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationModes).ToString(), Convert.ToInt32(ConstEnum.Code.CommunicationCategory).ToString(), null, null, null, true);
                    ViewBag.CommunicationModes = lstList; //JsonConvert.SerializeObject(lstList);//Json(new(key=lstList[key], JsonRequestBehavior.AllowGet);

                    lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationExecutionFrequency).ToString(), null, null, null, null, true);
                    ViewBag.CommunicationExecutionFrequency = lstList;//JsonConvert.SerializeObject(lstList);//Json(new(key=lstList[key], JsonRequestBehavior.AllowGet);

                    lstList = FillComboValues(ConstEnum.ComboType.TemplateList, null, null, null, null, null, true);
                    ViewBag.TemplateList = lstList;//JsonConvert.SerializeObject(lstList);//Json(new(key=lstList[key], JsonRequestBehavior.AllowGet);

                    if (objCommunicationRuleMasterModel.TriggerEventCodeId != null && objCommunicationRuleMasterModel.TriggerEventCodeId != "")
                    {
                        List <int> TagIds1 = objCommunicationRuleMasterModel.TriggerEventCodeId.Split(',').Select(int.Parse).ToList();

                        foreach (var a in TagIds1)
                        {
                            PopulateComboDTO obj = new PopulateComboDTO();
                            obj.Key   = a.ToString();
                            obj.Value = "";
                            objCommunicationRuleMasterModel.AssignedTriggerEventCodeId.Add(obj);
                        }
                    }
                    if (objCommunicationRuleMasterModel.OffsetEventCodeId != null && objCommunicationRuleMasterModel.OffsetEventCodeId != "")
                    {
                        List <int> TagIds1 = objCommunicationRuleMasterModel.OffsetEventCodeId.Split(',').Select(int.Parse).ToList();

                        foreach (var a in TagIds1)
                        {
                            PopulateComboDTO obj = new PopulateComboDTO();
                            obj.Key   = a.ToString();
                            obj.Value = "";
                            objCommunicationRuleMasterModel.AssignedOffsetEventCodeId.Add(obj);
                        }
                    }


                    FillGrid(ConstEnum.GridType.CommunicationRuleModesMasterList, Convert.ToString(objLoginUserDetails.LoggedInUserID), Convert.ToString(objCommunicationRuleMasterModel.RuleId), null, null, null);
                    ViewBag.showApplicabilityButton = false;
                    ViewBag.allowChangeStatus       = false;

                    ViewBag.isAllEdit            = false;
                    ViewBag.RuleId               = objCommunicationRuleMasterModel.RuleId;
                    ViewBag.UserId               = objLoginUserDetails.LoggedInUserID;
                    ViewBag.CommunicationMode_id = (objCommunicationRuleMasterModel.RuleCategoryCodeId == null ? 0 : objCommunicationRuleMasterModel.RuleCategoryCodeId);
                    if ((objCommunicationRuleMasterModel.IsApplicabilityDefined != null && objCommunicationRuleMasterModel.IsApplicabilityDefined == true) || objCommunicationRuleMasterModel.RuleStatusCodeId == Convert.ToInt32(InsiderTrading.Models.CommunicationRuleMasterModel.RuleStatusCode.Active))
                    {
                        ViewBag.allowChangeStatus = true;
                    }
                    if (InsiderTrading.Common.Common.CanPerform(InsiderTrading.Common.ConstEnum.UserActions.COMMUNICATION_RULES_ADD_RIGHT) || InsiderTrading.Common.Common.CanPerform(InsiderTrading.Common.ConstEnum.UserActions.COMMUNICATION_RULES_EDIT_RIGHT))
                    {
                        ViewBag.isAllEdit = true;
                        if (objCommunicationRuleMasterModel.RuleId != 0)
                        {
                            ViewBag.showApplicabilityButton = true;
                        }
                    }
                    //return View("Create", objCommunicationRuleMasterModel);
                    return(Json(new { status = false, error = ModelState.ToSerializedDictionary() }));

                    #endregion
                }
                using (var objCommunicationRuleMasterSL = new CommunicationRuleMasterSL())
                {
                    objCommunicationRuleMasterDTO = objCommunicationRuleMasterSL.SaveDetails(objCommunicationRuleMasterDTO, tblCommunicationRuleModeMasterType, objLoginUserDetails.CompanyDBConnectionString, objLoginUserDetails.LoggedInUserID);
                }

                string SuccessMessage          = Common.Common.getResource("cmu_msg_18020");
                bool   bIsApplicabilityDefined = ((objCommunicationRuleMasterModel.IsApplicabilityDefined != null && objCommunicationRuleMasterModel.IsApplicabilityDefined == true) ? true : false);
                if (bIsApplicabilityDefined && (objLoginUserDetails.UserTypeCodeId == ConstEnum.Code.Admin || objLoginUserDetails.UserTypeCodeId == ConstEnum.Code.COUserType))
                {
                    SuccessMessage = ((objCommunicationRuleMasterDTO.RuleStatusCodeId == Convert.ToInt32(InsiderTrading.Models.CommunicationRuleMasterModel.RuleStatusCode.Active) ? Common.Common.getResource("cmu_msg_18065") : Common.Common.getResource("cmu_msg_18066")));
                }
                return(Json(new
                {
                    status = true,
                    msg = SuccessMessage,
                    IsApplicabilityDefined = bIsApplicabilityDefined,
                    RuleId = objCommunicationRuleMasterDTO.RuleId
                }));
                //return RedirectToAction("Create", "CommunicationRuleMaster", new { acid = ConstEnum.UserActions.COMMUNICATION_RULES_EDIT_RIGHT, RuleId = objCommunicationRuleMasterDTO.RuleId}).Success(Common.Common.getResource("cmu_msg_18020"));
            }
            catch (Exception exp)
            {
                List <PopulateComboDTO> lstList = new List <PopulateComboDTO>();
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                ModelState.AddModelError("Error", sErrMessage);
                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationRuleCategory).ToString(), null, null, null, null, true);
                ViewBag.RuleCategoryCodeList = lstList;

                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.Events).ToString(), null, null, null, null, false);
                ViewBag.TriggerEventCodeList = lstList;

                lstList = FillComboValues(ConstEnum.ComboType.ListofEventsWithUserTypeForCommunicatioTriggerEvent, null, null, null, null, null, false);
                ViewBag.TriggerEventCodeWithUserTypeList = lstList;

                objCommunicationRuleMasterModel.AssignedTriggerEventCodeId = new List <PopulateComboDTO>();
                objCommunicationRuleMasterModel.AssignedOffsetEventCodeId  = new List <PopulateComboDTO>();

                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.Events).ToString(), null, null, null, null, false);
                ViewBag.OffsetEventCodeList = lstList;

                //lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationRuleStatus).ToString(), null, null, null, null, false);
                //ViewBag.RuleStatusCodeId = lstList;

                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationModes).ToString(), Convert.ToInt32(ConstEnum.Code.CommunicationCategory).ToString(), null, null, null, true);
                ViewBag.CommunicationModes = lstList; //JsonConvert.SerializeObject(lstList);//Json(new(key=lstList[key], JsonRequestBehavior.AllowGet);

                lstList = FillComboValues(ConstEnum.ComboType.ListOfCode, Convert.ToInt32(ConstEnum.CodeGroup.CommunicationExecutionFrequency).ToString(), null, null, null, null, true);
                ViewBag.CommunicationExecutionFrequency = lstList;//JsonConvert.SerializeObject(lstList);//Json(new(key=lstList[key], JsonRequestBehavior.AllowGet);

                lstList = FillComboValues(ConstEnum.ComboType.TemplateList, null, null, null, null, null, true);
                ViewBag.TemplateList = lstList;//JsonConvert.SerializeObject(lstList);//Json(new(key=lstList[key], JsonRequestBehavior.AllowGet);
                lstList = null;
                if (objCommunicationRuleMasterModel.TriggerEventCodeId != null && objCommunicationRuleMasterModel.TriggerEventCodeId != "")
                {
                    List <int> TagIds1 = objCommunicationRuleMasterModel.TriggerEventCodeId.Split(',').Select(int.Parse).ToList();

                    foreach (var a in TagIds1)
                    {
                        PopulateComboDTO obj = new PopulateComboDTO();
                        obj.Key   = a.ToString();
                        obj.Value = "";
                        objCommunicationRuleMasterModel.AssignedTriggerEventCodeId.Add(obj);
                    }
                }
                if (objCommunicationRuleMasterModel.OffsetEventCodeId != null && objCommunicationRuleMasterModel.OffsetEventCodeId != "")
                {
                    List <int> TagIds1 = objCommunicationRuleMasterModel.OffsetEventCodeId.Split(',').Select(int.Parse).ToList();

                    foreach (var a in TagIds1)
                    {
                        PopulateComboDTO obj = new PopulateComboDTO();
                        obj.Key   = a.ToString();
                        obj.Value = "";
                        objCommunicationRuleMasterModel.AssignedOffsetEventCodeId.Add(obj);
                    }
                }

                FillGrid(ConstEnum.GridType.CommunicationRuleModesMasterList, Convert.ToString(objLoginUserDetails.LoggedInUserID), Convert.ToString(objCommunicationRuleMasterModel.RuleId), null, null, null);
                ViewBag.showApplicabilityButton = false;
                ViewBag.UserAction           = 119;
                ViewBag.RuleId               = objCommunicationRuleMasterModel.RuleId;
                ViewBag.UserId               = objLoginUserDetails.LoggedInUserID;
                ViewBag.CommunicationMode_id = (objCommunicationRuleMasterModel.RuleCategoryCodeId == null ? 0 : objCommunicationRuleMasterModel.RuleCategoryCodeId);
                if ((objCommunicationRuleMasterModel.IsApplicabilityDefined != null && objCommunicationRuleMasterModel.IsApplicabilityDefined == true) || objCommunicationRuleMasterModel.RuleStatusCodeId == Convert.ToInt32(InsiderTrading.Models.CommunicationRuleMasterModel.RuleStatusCode.Active))
                {
                    ViewBag.allowChangeStatus = true;
                }
                if (InsiderTrading.Common.Common.CanPerform(InsiderTrading.Common.ConstEnum.UserActions.COMMUNICATION_RULES_ADD_RIGHT) || InsiderTrading.Common.Common.CanPerform(InsiderTrading.Common.ConstEnum.UserActions.COMMUNICATION_RULES_EDIT_RIGHT))
                {
                    ViewBag.isAllEdit = true;
                    if (objCommunicationRuleMasterModel.RuleId != 0)
                    {
                        ViewBag.showApplicabilityButton = true;
                    }
                }
                //return View("Create", objCommunicationRuleMasterModel);
                return(Json(new { status = false, error = ModelState.ToSerializedDictionary() }));
            }
            finally
            {
                objLoginUserDetails = null;
            }
        }
Example #15
0
        public async Task <ActionResult> Measurements(MeasurementQueryModel query, CancellationToken t)
        {
            CancellationToken disconnectedToken = Response.ClientDisconnectedToken;
            var timeOutToken = Request.TimedOutToken;
            var source       = CancellationTokenSource.CreateLinkedTokenSource(t, disconnectedToken, timeOutToken);

            Helpers.LoginHelper lh = new Helpers.LoginHelper();
            query.Key = lh.GetAuthenticationKey(this.HttpContext);
            if (query.Key != null)
            {
                ModelState.Remove("key");
                ModelState.Add("Key", new ModelState());
                ModelState.SetModelValue("Key", new ValueProviderResult(query.Key, query.Key, System.Globalization.CultureInfo.CurrentCulture));
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("RedirectToLogin"));
            }
            Repository r = new Repository();

            try
            {
                var measurements = await r.GetMeasurementsAsync(query, source.Token, true);

                if (measurements?.Count > 0 && !source.IsCancellationRequested)
                {
                    ViewBag.DataCount = measurements[0].Data.Count;
                    Helpers.DocumentHelper s = new Helpers.DocumentHelper();
                    string filename          = Session.SessionID + ".json";
                    string directoryPath     = Server.MapPath(Common.GlobalSettings.GetJSONPath);
                    s.SerializeJSONFile <List <MeasurementModel> >(measurements, directoryPath, filename);
                    ViewBag.DatetimeFormats  = Helpers.DatetimeFormatHelper.GetPossibleDatetimeFormats();
                    ViewBag.ExportModel      = new Models.ExportModel();
                    ViewBag.MeasurementCount = measurements.Count;
                }
                else
                {
                    source.Dispose();
                    return(Content("<span class='text-danger'>0 measurements found with given parameters.</span>"));
                }
                if (measurements.Count > 3000)
                {
                    var m = measurements.Take(3000);
                    measurements = m.ToList();
                }

                return(PartialView("~/Views/Export/Export.cshtml", measurements));
            }
            catch (KeyNotFoundException kex)
            {
                Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(kex, System.Web.HttpContext.Current.Request);
                return(RedirectToAction("RedirectToLogin"));
            }
            catch (UnauthorizedAccessException uex)
            {
                Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(uex, System.Web.HttpContext.Current.Request);
                return(RedirectToAction("RedirectToLogin"));
            }
            catch (OperationCanceledException canceled)
            {
                Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(canceled, System.Web.HttpContext.Current.Request);
                source.Dispose();
                return(Content("<span class='text-danger'>Request cancelled.</span>"));
            }
            catch (Exception ex)
            {
                Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(ex, System.Web.HttpContext.Current.Request);
                return(RedirectToAction("RedirectToLogin"));
            }
        }
Example #16
0
        public JsonResult UpdateResourceValue(ResourceModel objResourceModel, int acid)
        {
            bool             bReturn             = false;
            LoginUserDetails objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);
            ResourcesSL      objResourcesSL      = new ResourcesSL();
            ResourcesDTO     objResourcesDTO     = new ResourcesDTO();
            CompaniesSL      objCompaniesSL      = new CompaniesSL();
            bool             statusFlag          = false;
            var ErrorDictionary = new Dictionary <string, string>();

            Common.Common objCommon = new Common.Common();
            string        message   = string.Empty;

            try
            {
                if (!objCommon.ValidateCSRFForAJAX())
                {
                    return(Json(new
                    {
                        status = statusFlag,
                        Message = ErrorDictionary
                    }, JsonRequestBehavior.AllowGet));
                }
                Common.Common.CopyObjectPropertyByName(objResourceModel, objResourcesDTO);
                objResourcesDTO.LoggedInUserId = objLoginUserDetails.LoggedInUserID;
                bReturn = objResourcesSL.SaveDetails(objLoginUserDetails.CompanyDBConnectionString, objResourcesDTO);
                if (bReturn)
                {
                    objCompaniesSL.UpdateMasterCompanyDetails(Common.Common.getSystemConnectionString(), objLoginUserDetails.CompanyName, 1);
                    Common.Common.UpdateCompanyResources(objLoginUserDetails.CompanyDBConnectionString, objLoginUserDetails.CompanyName);
                    //return Json(new
                    //{
                    //    status = true,
                    //    Message = InsiderTrading.Common.Common.getResource("mst_msg_10049") //"Resource Update Successfully."

                    //}, JsonRequestBehavior.AllowGet);
                    statusFlag = true;
                    message    = InsiderTrading.Common.Common.getResource("mst_msg_10049");
                }
                else
                {
                    statusFlag = false;
                    message    = "Resource not saved.";
                }
                //return Json(new
                //{
                //    status = false,
                //    Message = "Resource not saved."

                //}, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exp)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());
                ModelState.AddModelError("error", sErrMessage);
                ErrorDictionary = GetModelStateErrorsAsString();
            }
            finally
            {
                objLoginUserDetails = null;
                objResourcesSL      = null;
                objResourcesDTO     = null;
                objCompaniesSL      = null;
            }
            return(Json(new
            {
                status = statusFlag,
                Message = message
            }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Apply(string nAllEmployeeFlag, string nAllInsiderFlag, string nAllEmployeeInsiderFlag, string nAllCoFlag, string nAllCorporateInsiderFlag, string nAllNonEmployeeInsiderFlag, string sMapToId, string sMapToTypeCodeId, string arrIncluded, string arrExcluded, string arrFilter, string arrnonInsEmpFilter, int acid, string __RequestVerificationToken = "", int formId = 0)
        {
            bool statusFlag = false;

            var ErrorDictionary = new Dictionary <string, string>();

            string[][] arrApplicabilityInclude = null;
            string[]   arrApplicabilityExclude = null;
            List <ApplicabilityFilter>          arrFilterList          = null;
            List <NonInsEmpApplicabilityFilter> arrFilterNonInsEmpList = null;

            LoginUserDetails objLoginUserDetails = null;

            DataTable tblApplicabilityUserIncludeExclude  = null;
            DataTable tblApplicabilityFilterType          = null;
            DataTable tblNonInsEmpApplicabilityFilterType = null;

            Common.Common objCommon = new Common.Common();
            try
            {
                if (!objCommon.ValidateCSRFForAJAX())
                {
                    return(Json(new
                    {
                        status = statusFlag,
                        Message = ErrorDictionary
                    }, JsonRequestBehavior.AllowGet));
                }
                objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails);

                if (arrIncluded != "")
                {
                    arrApplicabilityInclude = JsonConvert.DeserializeObject <string[][]>(arrIncluded);
                }

                if (arrExcluded != "")
                {
                    arrApplicabilityExclude = JsonConvert.DeserializeObject <string[]>(arrExcluded);
                }

                if (arrFilter != "")
                {
                    arrFilterList = JsonConvert.DeserializeObject <List <ApplicabilityFilter> >(arrFilter);
                }


                if (arrnonInsEmpFilter != "")
                {
                    arrFilterNonInsEmpList = JsonConvert.DeserializeObject <List <NonInsEmpApplicabilityFilter> >(arrnonInsEmpFilter);
                }

                tblApplicabilityUserIncludeExclude = new DataTable("ApplicabilityUserIncludeExcludeType");

                tblApplicabilityUserIncludeExclude.Columns.Add(new DataColumn("UserId", typeof(int)));
                tblApplicabilityUserIncludeExclude.Columns.Add(new DataColumn("InsiderTypeCodeId", typeof(int)));
                tblApplicabilityUserIncludeExclude.Columns.Add(new DataColumn("IncludeExcludeCodeId", typeof(int)));

                if (arrApplicabilityInclude != null)
                {
                    for (int i = 0; i < arrApplicabilityInclude.Length; i++)
                    {
                        int UserTypeCodeId = i == 0 ? ConstEnum.Code.EmployeeType : i == 1 ? ConstEnum.Code.CorporateUserType : i == 2 ? ConstEnum.Code.NonEmployeeType : i == 3 ? ConstEnum.Code.COUserType : ConstEnum.Code.EmployeeType;

                        DataRow row = null;

                        for (int j = 0; j < arrApplicabilityInclude[i].Length; j++)
                        {
                            row = tblApplicabilityUserIncludeExclude.NewRow();

                            row["UserId"]               = Convert.ToInt32(arrApplicabilityInclude[i][j]);
                            row["InsiderTypeCodeId"]    = UserTypeCodeId;
                            row["IncludeExcludeCodeId"] = InsiderTrading.Common.ConstEnum.Code.IncludeTypeCode;

                            tblApplicabilityUserIncludeExclude.Rows.Add(row);
                        }

                        row = null;
                    }
                }

                if (arrApplicabilityExclude != null)
                {
                    DataRow row = null;

                    for (int i = 0; i < arrApplicabilityExclude.Length; i++)
                    {
                        row = tblApplicabilityUserIncludeExclude.NewRow();

                        row["UserId"]               = Convert.ToInt32(arrApplicabilityExclude[i]);
                        row["InsiderTypeCodeId"]    = ConstEnum.Code.EmployeeType;
                        row["IncludeExcludeCodeId"] = InsiderTrading.Common.ConstEnum.Code.ExcludeTypeCode;

                        tblApplicabilityUserIncludeExclude.Rows.Add(row);
                    }

                    row = null;
                }

                tblApplicabilityFilterType = new DataTable("ApplicabilityFilterType");

                tblApplicabilityFilterType.Columns.Add(new DataColumn("ApplicabilityDtlsId", typeof(int)));
                tblApplicabilityFilterType.Columns.Add(new DataColumn("DepartmentCodeId", typeof(int)));
                tblApplicabilityFilterType.Columns.Add(new DataColumn("GradeCodeId", typeof(int)));
                tblApplicabilityFilterType.Columns.Add(new DataColumn("DesignationCodeId", typeof(int)));
                tblApplicabilityFilterType.Columns.Add(new DataColumn("CategoryCodeId", typeof(int)));
                tblApplicabilityFilterType.Columns.Add(new DataColumn("SubCategoryCodeId", typeof(int)));
                tblApplicabilityFilterType.Columns.Add(new DataColumn("RoleId", typeof(int)));

                tblNonInsEmpApplicabilityFilterType = new DataTable("NonInsEmpApplicabilityFilterType");

                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("ApplicabilityDtlsId", typeof(int)));
                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("DepartmentCodeId", typeof(int)));
                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("GradeCodeId", typeof(int)));
                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("DesignationCodeId", typeof(int)));
                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("CategoryCodeId", typeof(int)));
                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("SubCategoryCodeId", typeof(int)));
                tblNonInsEmpApplicabilityFilterType.Columns.Add(new DataColumn("RoleId", typeof(int)));
                if (arrFilterList != null)
                {
                    DataRow row = null;

                    foreach (var objFilter in arrFilterList)
                    {
                        row = tblApplicabilityFilterType.NewRow();

                        row["ApplicabilityDtlsId"] = 0;
                        row["DepartmentCodeId"]    = DBNull.Value;
                        row["GradeCodeId"]         = DBNull.Value;
                        row["DesignationCodeId"]   = DBNull.Value;
                        row["CategoryCodeId"]      = DBNull.Value;
                        row["SubCategoryCodeId"]   = DBNull.Value;
                        row["RoleId"] = DBNull.Value;

                        if (objFilter.ApplicabilityDtlsId != "" && objFilter.ApplicabilityDtlsId != "0")
                        {
                            row["ApplicabilityDtlsId"] = Convert.ToInt32(objFilter.ApplicabilityDtlsId);
                        }

                        if (objFilter.DepartmentId != "" && objFilter.DepartmentId != "0")
                        {
                            row["DepartmentCodeId"] = Convert.ToInt32(objFilter.DepartmentId);
                        }

                        if (objFilter.GradeId != "" && objFilter.GradeId != "0")
                        {
                            row["GradeCodeId"] = Convert.ToInt32(objFilter.GradeId);
                        }

                        if (objFilter.DesignationId != "" && objFilter.DesignationId != "0")
                        {
                            row["DesignationCodeId"] = Convert.ToInt32(objFilter.DesignationId);
                        }

                        if (objFilter.CategoryId != "" && objFilter.CategoryId != "0")
                        {
                            row["CategoryCodeId"] = Convert.ToInt32(objFilter.CategoryId);
                        }

                        if (objFilter.SubCategoryId != "" && objFilter.SubCategoryId != "0")
                        {
                            row["SubCategoryCodeId"] = Convert.ToInt32(objFilter.SubCategoryId);
                        }

                        if (objFilter.RoleId != "" && objFilter.RoleId != "0")
                        {
                            row["RoleId"] = Convert.ToInt32(objFilter.RoleId);
                        }

                        if (row["DesignationCodeId"] != DBNull.Value || row["GradeCodeId"] != DBNull.Value || row["DepartmentCodeId"] != DBNull.Value || row["CategoryCodeId"] != DBNull.Value || row["SubCategoryCodeId"] != DBNull.Value || row["RoleId"] != DBNull.Value)
                        {
                            tblApplicabilityFilterType.Rows.Add(row);
                        }
                    }

                    row = null;
                }
                if (arrFilterNonInsEmpList != null)
                {
                    DataRow row = null;

                    foreach (var objFilter in arrFilterNonInsEmpList)
                    {
                        row = tblNonInsEmpApplicabilityFilterType.NewRow();

                        row["ApplicabilityDtlsId"] = 0;
                        row["DepartmentCodeId"]    = DBNull.Value;
                        row["GradeCodeId"]         = DBNull.Value;
                        row["DesignationCodeId"]   = DBNull.Value;
                        row["CategoryCodeId"]      = DBNull.Value;
                        row["SubCategoryCodeId"]   = DBNull.Value;
                        row["RoleId"] = DBNull.Value;

                        if (objFilter.ApplicabilityDtlsId != "" && objFilter.ApplicabilityDtlsId != "0")
                        {
                            row["ApplicabilityDtlsId"] = Convert.ToInt32(objFilter.ApplicabilityDtlsId);
                        }

                        if (objFilter.DepartmentId != "" && objFilter.DepartmentId != "0")
                        {
                            row["DepartmentCodeId"] = Convert.ToInt32(objFilter.DepartmentId);
                        }

                        if (objFilter.GradeId != "" && objFilter.GradeId != "0")
                        {
                            row["GradeCodeId"] = Convert.ToInt32(objFilter.GradeId);
                        }

                        if (objFilter.DesignationId != "" && objFilter.DesignationId != "0")
                        {
                            row["DesignationCodeId"] = Convert.ToInt32(objFilter.DesignationId);
                        }

                        if (objFilter.CategoryId != "" && objFilter.CategoryId != "0")
                        {
                            row["CategoryCodeId"] = Convert.ToInt32(objFilter.CategoryId);
                        }

                        if (objFilter.SubCategoryId != "" && objFilter.SubCategoryId != "0")
                        {
                            row["SubCategoryCodeId"] = Convert.ToInt32(objFilter.SubCategoryId);
                        }

                        if (objFilter.RoleId != "" && objFilter.RoleId != "0")
                        {
                            row["RoleId"] = Convert.ToInt32(objFilter.RoleId);
                        }

                        if (row["DesignationCodeId"] != DBNull.Value || row["GradeCodeId"] != DBNull.Value || row["DepartmentCodeId"] != DBNull.Value || row["CategoryCodeId"] != DBNull.Value || row["SubCategoryCodeId"] != DBNull.Value || row["RoleId"] != DBNull.Value)
                        {
                            tblNonInsEmpApplicabilityFilterType.Rows.Add(row);
                        }
                    }

                    row = null;
                }
                using (ApplicabilitySL_OS objApplicabilitySl = new ApplicabilitySL_OS())
                {
                    int nCountOverlapPolicy = 0;

                    objApplicabilitySl.InsertDeleteApplicability(objLoginUserDetails.CompanyDBConnectionString, Convert.ToInt32(sMapToTypeCodeId), Convert.ToInt32(sMapToId), Convert.ToInt32(nAllEmployeeFlag), Convert.ToInt32(nAllInsiderFlag), Convert.ToInt32(nAllEmployeeInsiderFlag), Convert.ToInt32(nAllCoFlag), Convert.ToInt32(nAllCorporateInsiderFlag), Convert.ToInt32(nAllNonEmployeeInsiderFlag), tblApplicabilityFilterType, tblNonInsEmpApplicabilityFilterType, tblApplicabilityUserIncludeExclude, objLoginUserDetails.LoggedInUserID, out nCountOverlapPolicy);

                    statusFlag = true;

                    ErrorDictionary.Add("success", "Applicability saved successfully.");
                    ErrorDictionary.Add("CountOverlapPolicy", Convert.ToString(nCountOverlapPolicy));
                }
            }
            catch (Exception exp)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();

                string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString());

                ModelState.AddModelError("error", sErrMessage);

                ErrorDictionary = GetModelStateErrorsAsString();
            }
            finally
            {
                objLoginUserDetails = null;

                arrApplicabilityInclude = null;
                arrApplicabilityExclude = null;
                arrFilterList           = null;

                tblApplicabilityUserIncludeExclude = null;
                tblApplicabilityFilterType         = null;
            }

            return(Json(new
            {
                status = statusFlag,
                Message = ErrorDictionary
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(project project)
        {
            if (Request.Files != null && Request.Files.Count > 0)
            {
                foreach (string keyname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[keyname];
                    if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        //file upload
                        string ext = Path.GetExtension(file.FileName).ToLower();
                        if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".swf" && ext != ".fla")
                        {
                            ModelState.AddModelError(keyname, "Invalid file type");
                        }
                        else
                        {
                            try {
                                using (Image tmp = Image.FromStream(file.InputStream))
                                {
                                    //resize+crop
                                    int    width    = int.Parse(ConfigurationManager.AppSettings["Image_Project_Width"]);
                                    int    height   = int.Parse(ConfigurationManager.AppSettings["Image_Project_Height"]);
                                    string name     = getGuid() + ".jpg";
                                    string filepath = string.Format("projects/{0}", name);
                                    string address  = ConfigurationManager.AppSettings["AWSS3BucketUrl"] + filepath;

                                    //send
                                    using (Image resized = tmp.GetResizedImage(width, height, true))
                                    {
                                        var request = new PutObjectRequest().WithBucketName(ConfigurationManager.AppSettings["AWSS3Bucket"]).WithKey(filepath);
                                        using (MemoryStream buffer = new MemoryStream())
                                        {
                                            resized.Save(buffer, ImageHelper.GetJpgEncoder(), ImageHelper.GetJpgEncoderParameters(80));
                                            request.InputStream = buffer;
                                            AmazonS3Client s3Client = new AmazonS3Client();
                                            s3Client.PutObject(request);
                                        }
                                    }

                                    ModelState.Remove(keyname);
                                    ModelState.Add(keyname, new ModelState());
                                    ModelState.SetModelValue(keyname, new ValueProviderResult(address, address, null));
                                    project.Image = address;
                                }
                            }
                            catch (Exception ex) {
                                ModelState.AddModelError(keyname, "Upload error: " + ex.Message);
                            }
                        }

                        ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name");
                        ViewBag.UserID    = new SelectList(db.users.Where(x => x.Role == "admin" || x.Role == "publisher"), "UserID", "UserName", project.UserID);
                        return(View(project));
                    }
                }
            }

            if (ModelState.IsValid)
            {
                if (project.Image == null)
                {
                    project.Image = "https://s3-eu-west-1.amazonaws.com/localactors-webapp/projects/placeholder_project.png";
                }

                project.Enabled    = false;
                project.DateUpdate = DateTime.Now;
                db.projects.AddObject(project);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return(RedirectToAction("Create", "Update", new{ projectid = project.ProjectID }));
            }

            ViewBag.CountryID = new SelectList(db.countries, "CountryID", "Name");
            ViewBag.UserID    = new SelectList(db.users.Where(x => x.Role == "admin" || x.Role == "publisher"), "UserID", "UserName", project.UserID);
            return(View(project));
        }