예제 #1
0
        public static MsCrmResult SaveAnnotation(Annotation note, string relationName)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                IOrganizationService service = MSCRM.GetOrgService(true);

                int splitLength = note.FileName.Split('.').Length;
                note.FilePath = Guid.NewGuid() + "." + note.FileName.Split('.')[splitLength - 1].ToLower();

                returnValue = AttachmentFileHelper.CreateAttachmentFile(note, service);

                if (returnValue.Success)
                {
                    byte[] data = Convert.FromBase64String(note.File);
                    //File.WriteAllBytes(HostingEnvironment.MapPath("~/attachments") + "/" + note.FilePath, data);
                    File.WriteAllBytes(@Globals.AttachmentFolder + @"\" + note.FilePath, data);

                    note.AttachmentFile = new EntityReference("new_attachment", returnValue.CrmId);
                    returnValue         = AttachmentFileHelper.AssociateAttachmentToEntity(returnValue.CrmId, note.Object, relationName, service);
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }
예제 #2
0
        public static MsCrmResult SaveObjectProfileImage(Annotation note, string fieldName, SqlDataAccess sda)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                IOrganizationService service = MSCRM.GetOrgService(true);

                int splitLength = note.FileName.Split('.').Length;
                note.FilePath = Guid.NewGuid() + "." + note.FileName.Split('.')[splitLength - 1].ToLower();

                byte[] data = Convert.FromBase64String(note.File);

                //File.WriteAllBytes(HostingEnvironment.MapPath("~/attachments") + "/" + note.FilePath, data);
                File.WriteAllBytes(@Globals.AttachmentFolder + @"\" + note.FilePath, data);

                #region | DELETE PREVIOUS IMAGE FILE |

                string fileName = AttachmentFileHelper.GetEntityProfileImageFileName(note.Object.Id.ToString(), note.Object.LogicalName, fieldName, sda);

                if (!string.IsNullOrEmpty(fileName))
                {
                    //string filePath = HostingEnvironment.MapPath("~/attachments") + "/" + fileName;
                    string filePath = @Globals.AttachmentFolder + @"\" + fileName;

                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }
                }

                #endregion

                #region | UPDATE CRM ENTITY |

                Entity ent = new Entity(note.Object.LogicalName.ToLower());
                ent[note.Object.LogicalName.ToLower() + "id"] = note.Object.Id;
                ent[fieldName] = note.FilePath;

                service.Update(ent);

                #endregion

                returnValue.Success = true;
                returnValue.Result  = note.FilePath;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }
예제 #3
0
        public static MsCrmResult UpdateProfileImage(Guid userId, string fileName, string fieldName, SqlDataAccess sda, IOrganizationService service)
        {
            MsCrmResult returnValue = new MsCrmResult();

            try
            {
                #region | DELETE PREVIOUS IMAGE FILE |

                string oldFileName = AttachmentFileHelper.GetEntityProfileImageFileName(userId.ToString(), "new_user", fieldName, sda);

                if (!string.IsNullOrEmpty(oldFileName))
                {
                    //string filePath = HostingEnvironment.MapPath("~/attachments") + "/" + oldFileName;
                    string filePath = @Globals.AttachmentFolder + @"\" + oldFileName;

                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }
                }

                #endregion

                #region | UPDATE CRM ENTITY |

                Entity ent = new Entity("new_user");
                ent.Id         = userId;
                ent[fieldName] = fileName;

                service.Update(ent);

                #endregion

                returnValue.Success = true;
                returnValue.Result  = fileName;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }
예제 #4
0
        public static MsCrmResultObject GetArticleInfo(Guid articleId, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                #region | SQL QUERY |
                string query = @"SELECT
                                        A.new_articleId ArticleId
	                                    ,A.new_name Name
	                                    ,A.new_summary Summary
	                                    ,A.new_content [Description]
	                                    ,A.new_imageurl [Image]
	                                    ,CAST({2}.dbo.fn_UTCToTzSpecificLocalTime(A.CreatedOn, us.TimeZoneBias, us.TimeZoneDaylightBias,us.TimeZoneDaylightYear, us.TimeZoneDaylightMonth, us.TimeZoneDaylightDay, us.TimeZoneDaylightHour,us.TimeZoneDaylightMinute, us.TimeZoneDaylightSecond, 0, us.TimeZoneDaylightDayOfWeek,us.TimeZoneStandardBias, us.TimeZoneStandardYear, us.TimeZoneStandardMonth, us.TimeZoneStandardDay,us.TimeZoneStandardHour, us.TimeZoneStandardMinute, us.TimeZoneStandardSecond, 0,us.TimeZoneStandardDayOfWeek) as DATETIME) CreatedOn
                                FROM
	                                new_article A (NoLock)
                                 INNER JOIN 
	                                dbo.UserSettingsBase US (NoLock)
	                                ON 
	                                US.SystemUserId ='{1}'
                                WHERE
	                                A.new_articleId = '{0}'"    ;
                #endregion

                DataTable dt = sda.getDataTable(string.Format(query, articleId, Globals.AdminId, Globals.DatabaseName));
                if (dt != null && dt.Rows.Count > 0)
                {
                    Article _article = new Article();
                    _article.ArticleId       = (Guid)dt.Rows[0]["ArticleId"];
                    _article.Name            = dt.Rows[0]["Name"].ToString();
                    _article.Summary         = dt.Rows[0]["Summary"].ToString();
                    _article.Description     = dt.Rows[0]["Description"].ToString();
                    _article.ImagePath       = dt.Rows[0]["Image"] != DBNull.Value ? dt.Rows[0]["Image"].ToString() : "no_image_available.png";
                    _article.CreatedOnString = dt.Rows[0]["CreatedOn"] != DBNull.Value ? ((DateTime)dt.Rows[0]["CreatedOn"]).ToString("dd MMMM yyyy ddddd HH:mm", new CultureInfo("tr-TR", false)) : string.Empty;

                    #region | GET COMMENTS |
                    MsCrmResultObject commentResult = CommentHelper.GetArticleComments(articleId, sda);
                    if (commentResult.Success)
                    {
                        _article.CommentList = (List <Comment>)commentResult.ReturnObject;
                    }
                    #endregion

                    #region | GET ATTACHMENTS |
                    MsCrmResultObject attachmentResult = AttachmentFileHelper.GetArticleAttachmentFiles(articleId, sda);
                    if (attachmentResult.Success)
                    {
                        _article.AttachmentFileList = (List <AttachmentFile>)attachmentResult.ReturnObject;
                    }
                    #endregion

                    returnValue.Success      = true;
                    returnValue.ReturnObject = _article;
                }
                else
                {
                    returnValue.Success = true;
                    returnValue.Result  = "M020"; //"İstenilen makaleye ait detay bulunamadı!";
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }
            return(returnValue);
        }
예제 #5
0
        public static MsCrmResultObject GetEducationInfo(Guid educationId, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                #region | SQL QUERY |
                string query = @"SELECT
	                                E.new_educationId EducationId
	                                ,E.new_name Name
	                                ,E.new_summary Summary
	                                ,E.new_content [Description]
	                                ,E.new_imageurl [Image]
	                                ,CAST({2}.dbo.fn_UTCToTzSpecificLocalTime(E.CreatedOn, us.TimeZoneBias, us.TimeZoneDaylightBias,us.TimeZoneDaylightYear, us.TimeZoneDaylightMonth, us.TimeZoneDaylightDay, us.TimeZoneDaylightHour,us.TimeZoneDaylightMinute, us.TimeZoneDaylightSecond, 0, us.TimeZoneDaylightDayOfWeek,us.TimeZoneStandardBias, us.TimeZoneStandardYear, us.TimeZoneStandardMonth, us.TimeZoneStandardDay,us.TimeZoneStandardHour, us.TimeZoneStandardMinute, us.TimeZoneStandardSecond, 0,us.TimeZoneStandardDayOfWeek) as DATETIME) CreatedOn
                                FROM
	                                new_education E (NoLock)
                                INNER JOIN 
	                                dbo.UserSettingsBase US (NoLock)
	                                ON 
	                                US.SystemUserId ='{1}'
                                WHERE
	                                E.new_educationId = '{0}'"    ;
                #endregion

                DataTable dt = sda.getDataTable(string.Format(query, educationId, Globals.AdminId, Globals.DatabaseName));
                if (dt != null && dt.Rows.Count > 0)
                {
                    Education _education = new Education();
                    _education.EducationId     = (Guid)dt.Rows[0]["EducationId"];
                    _education.Name            = dt.Rows[0]["Name"].ToString();
                    _education.Summary         = dt.Rows[0]["Summary"].ToString();
                    _education.Description     = dt.Rows[0]["Description"].ToString();
                    _education.ImagePath       = dt.Rows[0]["Image"] != DBNull.Value ? dt.Rows[0]["Image"].ToString() : "no_image_available.png";
                    _education.CreatedOnString = dt.Rows[0]["CreatedOn"] != DBNull.Value ? ((DateTime)dt.Rows[0]["CreatedOn"]).ToString("dd MMMM yyyy ddddd HH:mm", new CultureInfo("tr-TR", false)) : string.Empty;

                    MsCrmResultObject resultLike = LikeHelper.GetEntityLikeInfo(_education.EducationId, "new_graffiti", sda);

                    if (resultLike.Success)
                    {
                        _education.LikeDetail = (LikeInfo)resultLike.ReturnObject;
                    }

                    #region | GET COMMENTS |
                    MsCrmResultObject commentResult = CommentHelper.GetEducationComments(educationId, sda);
                    if (commentResult.Success)
                    {
                        _education.CommentList = (List <Comment>)commentResult.ReturnObject;
                    }
                    #endregion

                    #region | GET ATTACHMENTS |
                    MsCrmResultObject attachmentResult = AttachmentFileHelper.GetEducationAttachmentFiles(educationId, sda);
                    if (attachmentResult.Success)
                    {
                        _education.AttachmentFileList = (List <AttachmentFile>)attachmentResult.ReturnObject;
                    }
                    #endregion

                    returnValue.Success      = true;
                    returnValue.ReturnObject = _education;
                }
                else
                {
                    returnValue.Success = true;
                    returnValue.Result  = "M017"; //"Eğitim kaydına ulaşılamadı.";
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }

            return(returnValue);
        }
예제 #6
0
        public static MsCrmResultObject GetAnnouncementInfo(Guid announcementId, SqlDataAccess sda)
        {
            MsCrmResultObject returnValue = new MsCrmResultObject();

            try
            {
                #region | SQL QUERY |
                string query = @"SELECT 
	                                A.new_announcementId Id
	                                ,A.new_name Name
	                                ,A.new_content Content
	                                ,A.new_imageurl ImageUrl
                                    ,CAST({2}.dbo.fn_UTCToTzSpecificLocalTime(A.CreatedOn, us.TimeZoneBias, us.TimeZoneDaylightBias,us.TimeZoneDaylightYear, us.TimeZoneDaylightMonth, us.TimeZoneDaylightDay, us.TimeZoneDaylightHour,us.TimeZoneDaylightMinute, us.TimeZoneDaylightSecond, 0, us.TimeZoneDaylightDayOfWeek,us.TimeZoneStandardBias, us.TimeZoneStandardYear, us.TimeZoneStandardMonth, us.TimeZoneStandardDay,us.TimeZoneStandardHour, us.TimeZoneStandardMinute, us.TimeZoneStandardSecond, 0,us.TimeZoneStandardDayOfWeek) as DATETIME) CreatedOn
                                FROM
	                                new_announcement A (NoLock)
                                INNER JOIN
	                                SystemUser SU (NoLock)
	                                ON
	                                SU.SystemUserId = '{1}'
                                INNER JOIN 
	                                dbo.UserSettingsBase US (NoLock)
	                                ON 
	                                US.SystemUserId =SU.SystemUserId
                                WHERE
	                                A.new_announcementId = '{0}'
                                ORDER BY 
	                                A.CreatedOn DESC"    ;
                #endregion

                DataTable dt = sda.getDataTable(string.Format(query, announcementId, Globals.AdminId, Globals.DatabaseName));

                if (dt != null && dt.Rows.Count > 0)
                {
                    Announcement _announcement = new Announcement();
                    _announcement.AnnouncementId = (Guid)dt.Rows[0]["Id"];
                    _announcement.Caption        = dt.Rows[0]["Name"] != DBNull.Value ? dt.Rows[0]["Name"].ToString() : string.Empty;
                    _announcement.Description    = dt.Rows[0]["Content"] != DBNull.Value ? dt.Rows[0]["Content"].ToString() : string.Empty;
                    _announcement.ImagePath      = dt.Rows[0]["ImageUrl"] != DBNull.Value ? dt.Rows[0]["ImageUrl"].ToString() : "no_image_available.png";

                    if (dt.Rows[0]["CreatedOn"] != DBNull.Value)
                    {
                        _announcement.CreatedOnString = dt.Rows[0]["CreatedOn"] != DBNull.Value ? ((DateTime)dt.Rows[0]["CreatedOn"]).ToString("dd MMMM yyyy ddddd HH:mm", new CultureInfo("tr-TR", false)) : string.Empty;
                        _announcement.CreatedOn       = (DateTime)dt.Rows[0]["CreatedOn"];
                    }

                    #region | GET ATTACHMENTS |
                    MsCrmResultObject attachmentResult = AttachmentFileHelper.GetAnnouncementAttachmentFiles(announcementId, sda);
                    if (attachmentResult.Success)
                    {
                        _announcement.AttachmentFileList = (List <AttachmentFile>)attachmentResult.ReturnObject;
                    }
                    #endregion

                    returnValue.Success      = true;
                    returnValue.ReturnObject = _announcement;
                }
                else
                {
                    returnValue.Result = "M026"; //"İlgili duyuruya ait bilgiye ulaşılamadı.";
                }
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Result  = ex.Message;
            }

            return(returnValue);
        }