public virtual Project SaveOrUpdate(Project project, bool notifyManager, bool isImport) { if (project == null) { throw new ArgumentNullException("project"); } // check guest responsible if (ProjectSecurity.IsVisitor(project.Responsible)) { ProjectSecurity.CreateGuestSecurityException(); } project.LastModifiedBy = SecurityContext.CurrentAccount.ID; project.LastModifiedOn = TenantUtil.DateTimeNow(); if (project.ID == 0) { if (project.CreateBy == default(Guid)) { project.CreateBy = SecurityContext.CurrentAccount.ID; } if (project.CreateOn == default(DateTime)) { project.CreateOn = TenantUtil.DateTimeNow(); } ProjectSecurity.DemandCreate <Project>(null); DaoFactory.ProjectDao.Create(project); FactoryIndexer <ProjectsWrapper> .IndexAsync(project); } else { var oldProject = DaoFactory.ProjectDao.GetById(new List <int> { project.ID }).FirstOrDefault(); ProjectSecurity.DemandEdit(oldProject); DaoFactory.ProjectDao.Update(project); if (!project.Private) { ResetTeamSecurity(oldProject); } FactoryIndexer <ProjectsWrapper> .UpdateAsync(project); } if (notifyManager && !DisableNotifications && !project.Responsible.Equals(SecurityContext.CurrentAccount.ID)) { NotifyClient.Instance.SendAboutResponsibleByProject(project.Responsible, project); } return(project); }
public virtual int Update(ContactInfo contactInfo) { var result = UpdateInDb(contactInfo); if (contactInfo.InfoType == ContactInfoType.Email) { var infos = GetList(contactInfo.ContactID, ContactInfoType.Email, null, null); FactoryIndexer <EmailWrapper> .Update(new EmailWrapper { Id = contactInfo.ContactID, EmailInfoWrapper = infos.Select(r => (EmailInfoWrapper)r).ToList() }, UpdateAction.Replace, r => r.EmailInfoWrapper); } FactoryIndexer <InfoWrapper> .UpdateAsync(contactInfo); return(result); }
protected void Page_Load(object sender, EventArgs e) { _settings = Community.Forum.ForumManager.Settings; _forumManager = _settings.ForumManager; Utility.RegisterTypeForAjax(typeof(TagSuggest)); _subject = ""; int idTopic = 0; if (!String.IsNullOrEmpty(Request[_settings.TopicParamName])) { try { idTopic = Convert.ToInt32(Request[_settings.TopicParamName]); } catch { idTopic = 0; } } if (idTopic == 0) { Response.Redirect(_forumManager.PreviousPage.Url); return; } topicId = idTopic; EditableTopic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (EditableTopic == null) { Response.Redirect(_forumManager.PreviousPage.Url); return; } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicEdit, EditableTopic)) { Response.Redirect(_forumManager.PreviousPage.Url); return; } _subject = EditableTopic.Title; _tagString = String.Join(",", EditableTopic.Tags.Select(x => x.Name)); _tagValues = JsonConvert.SerializeObject(EditableTopic.Tags.Select(x => new List <object> { x.Name, x.ID })); if (EditableTopic.Type == TopicType.Informational) { _pollMaster.Visible = false; } else { _pollMaster.QuestionFieldID = "forum_subject"; if (IsPostBack == false) { var question = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, EditableTopic.QuestionID); _pollMaster.Singleton = (question.Type == QuestionType.OneAnswer); _pollMaster.Name = question.Name; _pollMaster.ID = question.ID.ToString(); foreach (var variant in question.AnswerVariants) { _pollMaster.AnswerVariants.Add(new PollFormMaster.AnswerViarint() { ID = variant.ID.ToString(), Name = variant.Name }); } } } #region IsPostBack if (IsPostBack) { if (EditableTopic.Type == TopicType.Informational) { _subject = Request["forum_subject"].Trim(); } else { _subject = (_pollMaster.Name ?? "").Trim(); } if (String.IsNullOrEmpty(_subject)) { _subject = ""; _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorSubjectEmpty + "</div>"; return; } if (EditableTopic.Type == TopicType.Poll && _pollMaster.AnswerVariants.Count < 2) { _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorPollVariantCount + "</div>"; return; } if (!String.IsNullOrEmpty(Request["forum_tags"])) { _tagString = Request["forum_tags"].Trim(); } else { _tagString = ""; } if (!String.IsNullOrEmpty(Request["forum_search_tags"])) { _tagValues = Request["forum_search_tags"].Trim(); } EditableTopic.Title = _subject; if (_forumManager.ValidateAccessSecurityAction(ForumAction.TagCreate, new Thread() { ID = EditableTopic.ThreadID })) { var removeTags = EditableTopic.Tags; EditableTopic.Tags = CreateTags(); removeTags.RemoveAll(t => EditableTopic.Tags.Find(nt => nt.ID == t.ID) != null); foreach (var tag in EditableTopic.Tags) { if (tag.ID == 0) { ForumDataProvider.CreateTag(TenantProvider.CurrentTenantID, EditableTopic.ID, tag.Name, tag.IsApproved); } else { ForumDataProvider.AttachTagToTopic(TenantProvider.CurrentTenantID, tag.ID, EditableTopic.ID); } } removeTags.ForEach(t => { ForumDataProvider.RemoveTagFromTopic(TenantProvider.CurrentTenantID, t.ID, EditableTopic.ID); }); } try { if (EditableTopic.Type == TopicType.Poll) { List <AnswerVariant> variants = new List <AnswerVariant>(); int i = 1; foreach (var answVariant in _pollMaster.AnswerVariants) { variants.Add(new AnswerVariant() { ID = (String.IsNullOrEmpty(answVariant.ID) ? 0 : Convert.ToInt32(answVariant.ID)), Name = answVariant.Name, SortOrder = i - 1 }); i++; } ForumDataProvider.UpdatePoll(TenantProvider.CurrentTenantID, EditableTopic.QuestionID, _pollMaster.Singleton ? QuestionType.OneAnswer : QuestionType.SeveralAnswer, EditableTopic.Title, variants); } ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, EditableTopic.ID, EditableTopic.Title, EditableTopic.Sticky, EditableTopic.Closed); FactoryIndexer <TopicWrapper> .UpdateAsync(EditableTopic); _errorMessage = "<div class=\"okBox\">" + Resources.ForumUCResource.SuccessfullyEditTopicMessage + "</div>"; Response.Redirect(_forumManager.PreviousPage.Url); } catch (Exception ex) { _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>"; return; } } #endregion }
protected void SaveOrUpdateCase(object sender, CommandEventArgs e) { try { using (var scope = DIHelper.Resolve()) { var daoFactory = scope.Resolve <DaoFactory>(); int caseID; if (TargetCase != null) { caseID = TargetCase.ID; TargetCase.Title = Request["caseTitle"]; daoFactory.CasesDao.UpdateCases(TargetCase); FactoryIndexer <CasesWrapper> .UpdateAsync(TargetCase); MessageService.Send(HttpContext.Current.Request, MessageAction.CaseUpdated, MessageTarget.Create(TargetCase.ID), TargetCase.Title); SetPermission(TargetCase); } else { caseID = daoFactory.CasesDao.CreateCases(Request["caseTitle"]); var newCase = daoFactory.CasesDao.GetByID(caseID); FactoryIndexer <CasesWrapper> .IndexAsync(newCase); MessageService.Send(HttpContext.Current.Request, MessageAction.CaseCreated, MessageTarget.Create(newCase.ID), newCase.Title); SetPermission(newCase); } daoFactory.CasesDao.SetMembers(caseID, !String.IsNullOrEmpty(Request["memberID"]) ? Request["memberID"].Split(',').Select( id => Convert.ToInt32(id)).ToArray() : new List <int>().ToArray()); var assignedTags = Request["baseInfo_assignedTags"]; if (assignedTags != null) { var oldTagList = daoFactory.TagDao.GetEntityTags(EntityType.Case, caseID); foreach (var tag in oldTagList) { daoFactory.TagDao.DeleteTagFromEntity(EntityType.Case, caseID, tag); } if (assignedTags != string.Empty) { var tagListInfo = JObject.Parse(assignedTags)["tagListInfo"].ToArray(); var newTagList = tagListInfo.Select(t => t.ToString()).ToArray(); daoFactory.TagDao.SetTagToEntity(EntityType.Case, caseID, newTagList); } } foreach (var customField in Request.Form.AllKeys) { if (!customField.StartsWith("customField_")) { continue; } int fieldID = Convert.ToInt32(customField.Split('_')[1]); string fieldValue = Request.Form[customField]; if (String.IsNullOrEmpty(fieldValue) && TargetCase == null) { continue; } daoFactory.CustomFieldDao.SetFieldValue(EntityType.Case, caseID, fieldID, fieldValue); } Response.Redirect( string.Compare(e.CommandArgument.ToString(), "0", StringComparison.OrdinalIgnoreCase) == 0 ? string.Format("Cases.aspx?id={0}", caseID) : "Cases.aspx?action=manage", false); Context.ApplicationInstance.CompleteRequest(); } } catch (Exception ex) { LogManager.GetLogger("ASC.CRM").Error(ex); var cookie = HttpContext.Current.Request.Cookies.Get(ErrorCookieKey); if (cookie == null) { cookie = new HttpCookie(ErrorCookieKey) { Value = ex.Message }; HttpContext.Current.Response.Cookies.Add(cookie); } } }