예제 #1
0
        public void Execute(IServiceProvider serviceProvider)
        {
            SqlDataAccess sda = null;

            try
            {
                sda = new SqlDataAccess();
                sda.openConnection(Globals.ConnectionString);

                #region | SERVICE |
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                #region | Validate Request |
                //Target yoksa veya Entity tipinde değilse, devam etme.
                if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity))
                {
                    return;
                }
                #endregion

                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                #endregion

                Entity entity = (Entity)context.InputParameters["Target"];

                #region |DEFINE IMAGE IF EXISTS|
                Entity postImage = null;
                if (context.PostEntityImages.Contains("PostImage") && context.PostEntityImages["PostImage"] is Entity)
                {
                    postImage = (Entity)context.PostEntityImages["PostImage"];
                }
                #endregion

                #region | VARIABLES |
                List<ScoreLimit> lstLimits = new List<ScoreLimit>();

                EntityReference portal = null;
                EntityReference user = null;

                if (postImage.Contains("new_portalid") && postImage["new_portalid"] != null)
                {
                    portal = (EntityReference)postImage["new_portalid"];
                }

                if (postImage.Contains("new_userid") && postImage["new_userid"] != null)
                {
                    user = (EntityReference)postImage["new_userid"];
                }
                #endregion

                if (entity.Contains("statuscode") && entity["statuscode"] != null && ((OptionSetValue)entity["statuscode"]).Value == 1)
                {
                    MsCrmResultObject limitRes = ScoreHelper.GetScoreLimitsByType(ScoreType.ForumSubject, sda);

                    if (limitRes.Success)
                    {
                        lstLimits = (List<ScoreLimit>)limitRes.ReturnObject;

                        for (int i = 0; i < lstLimits.Count; i++)
                        {
                            int recCount = 0;
                            DateTime start = GeneralHelper.GetStartDateByScorePeriod(lstLimits[i].Period);
                            DateTime end = GeneralHelper.GetEndDateByScorePeriod(lstLimits[i].Period);

                            recCount = ForumHelper.GetUserForumSubjectCount(portal.Id, user.Id, start, end, sda);

                            if (lstLimits[i].Frequency >= recCount)
                            {
                                Score sc = new Score()
                                {
                                    Point = lstLimits[i].Point,
                                    Portal = portal,
                                    User = user,
                                    ScoreType = ScoreType.ForumSubject
                                };

                                MsCrmResult scoreRes = ScoreHelper.CreateScore(sc, service);

                                break;
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                //LOG
                throw new InvalidPluginExecutionException(ex.Message);
            }
            finally
            {
                if (sda != null)
                    sda.closeConnection();
            }
        }
예제 #2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            SqlDataAccess sda = null;

            try
            {
                sda = new SqlDataAccess();
                sda.openConnection(Globals.ConnectionString);

                #region | SERVICE |
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                #region | Validate Request |
                //Target yoksa veya Entity tipinde değilse, devam etme.
                if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity))
                {
                    return;
                }
                #endregion

                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                #endregion

                Entity entity = (Entity)context.InputParameters["Target"];

                #region | VARIABLES |
                bool hasMedia = false;

                List<ScoreLimit> lstLimits = new List<ScoreLimit>();

                EntityReference portal = null;
                EntityReference user = null;

                if (entity.Contains("new_hasmedia") && entity["new_hasmedia"] != null)
                {
                    hasMedia = (bool)entity["new_hasmedia"];
                }

                if (entity.Contains("new_portalid") && entity["new_portalid"] != null)
                {
                    portal = (EntityReference)entity["new_portalid"];
                }

                if (entity.Contains("new_userid") && entity["new_userid"] != null)
                {
                    user = (EntityReference)entity["new_userid"];
                }
                #endregion

                MsCrmResultObject limitRes = new MsCrmResultObject();

                if (hasMedia)
                    limitRes = ScoreHelper.GetScoreLimitsByType(ScoreType.GraffitiMedia, sda);
                else
                    limitRes = ScoreHelper.GetScoreLimitsByType(ScoreType.GraffitiText, sda);

                if (limitRes.Success)
                {
                    lstLimits = (List<ScoreLimit>)limitRes.ReturnObject;

                    for (int i = 0; i < lstLimits.Count; i++)
                    {
                        int recCount = 0;
                        DateTime start = GeneralHelper.GetStartDateByScorePeriod(lstLimits[i].Period);
                        DateTime end = GeneralHelper.GetEndDateByScorePeriod(lstLimits[i].Period);

                        recCount = GraffitiHelper.GetUserGraffitiCount(portal.Id, user.Id, start, end, hasMedia, sda);

                        if (lstLimits[i].Frequency >= recCount)
                        {
                            Score sc = new Score()
                            {
                                Point = lstLimits[i].Point,
                                Portal = portal,
                                User = user,
                                ScoreType = (hasMedia ? ScoreType.GraffitiMedia : ScoreType.GraffitiText)
                            };

                            MsCrmResult scoreRes = ScoreHelper.CreateScore(sc, service);

                            break;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                //LOG
                throw new InvalidPluginExecutionException(ex.Message);
            }
            finally
            {
                if (sda != null)
                    sda.closeConnection();
            }
        }
예제 #3
0
        public void ProcessRequest(HttpContext context)
        {
            FileLogHelper.LogEvent("Kale-uploadHelper", @"C:\DO\");

            context.Response.ContentType = "application/json";

            object returnValue = null;

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            try
            {
                _sda = new SqlDataAccess();
                _sda.openConnection(Globals.ConnectionString);

                string operation = context.Request.QueryString["operation"];
                string userId = context.Request.QueryString["userid"];
                string graffitiId = context.Request.QueryString["graffitiId"];

                if (operation == "1" && !string.IsNullOrEmpty(userId)) //Profile resmi güncelleme
                {
                    returnValue = new MsCrmResult();

                    _service = MSCRM.GetOrgService(true);
                    HttpPostedFile file = context.Request.Files[0];

                    returnValue = SaveProfileImage(userId, file, context);
                }
                else if (operation == "2" && !string.IsNullOrEmpty(graffitiId)) //Duvar yazısı resim ekleme
                {
                    returnValue = new MsCrmResult();

                    _service = MSCRM.GetOrgService(true);
                    HttpPostedFile file = context.Request.Files[0];

                    returnValue = SaveGraffitiImage(new Guid(graffitiId), file, context);
                }
                else
                {
                    ((MsCrmResultObject)returnValue).Result = "Eksik veya yanlış parametre.";
                }
            }
            catch (Exception ex)
            {
                returnValue = new MsCrmResult();
                ((MsCrmResult)returnValue).HasException = true;
                ((MsCrmResult)returnValue).Result = ex.Message;

            }
            finally
            {
                if (_sda != null)
                {
                    _sda.closeConnection();

                }
            }

            var dataRes = serializer.Serialize(returnValue);
            context.Response.Write(dataRes);
        }
예제 #4
0
        public void Execute(IServiceProvider serviceProvider)
        {
            SqlDataAccess sda = null;

            try
            {
                sda = new SqlDataAccess();
                sda.openConnection(Globals.ConnectionString);

                #region | SERVICE |
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                #region | Validate Request |
                //Target yoksa veya Entity tipinde değilse, devam etme.
                if (!context.InputParameters.Contains("Target") || !(context.InputParameters["Target"] is Entity))
                {
                    return;
                }
                #endregion

                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                #endregion

                Entity entity = (Entity)context.InputParameters["Target"];

                #region | VARIABLES |

                EntityReference userId = null;
                EntityReference cityId = null;
                EntityReference townId = null;
                AssemblerInfo assemblerInfo = null;

                string customerFirstName = null;
                string customerLastName = null;
                string customerMobilePhone = null;
                string customerFullName = null;
                string assemblerFullName = null;

                if (entity.Contains("new_userid") && entity["new_userid"] != null)
                {
                    userId = (EntityReference)entity["new_userid"];

                    MsCrmResultObj<AssemblerInfo> resultAssembler = AssemblyRequestHelper.GetAssemblerInfo(userId.Id, sda);

                    if (resultAssembler.Success)
                    {
                        assemblerInfo = resultAssembler.ReturnObject;
                    }
                    else
                    {
                        throw new Exception("Anahtarcı bilgisi alınamadı.Hata:" + resultAssembler.Result);
                    }
                }

                if (entity.Contains("new_cityid") && entity["new_cityid"] != null)
                {
                    cityId = (EntityReference)entity["new_cityid"];
                }

                if (entity.Contains("new_townid") && entity["new_townid"] != null)
                {
                    townId = (EntityReference)entity["new_townid"];
                }

                if (entity.Contains("new_firstname") && entity["new_firstname"] != null)
                {
                    customerFirstName = entity["new_firstname"].ToString();
                }

                if (entity.Contains("new_lastname") && entity["new_lastname"] != null)
                {
                    customerLastName = entity["new_lastname"].ToString();
                }

                if (entity.Contains("new_mobilephone") && entity["new_mobilephone"] != null)
                {
                    customerMobilePhone = entity["new_mobilephone"].ToString();
                }

                if (!string.IsNullOrWhiteSpace(customerFirstName) && !string.IsNullOrWhiteSpace(customerLastName))
                {
                    customerFullName = customerFirstName + " " + customerLastName;
                }

                if (assemblerInfo != null && !string.IsNullOrWhiteSpace(assemblerInfo.FirstName) && !string.IsNullOrWhiteSpace(assemblerInfo.LastName))
                {
                    assemblerFullName = assemblerInfo.FirstName + " " + assemblerInfo.LastName;
                }

                #endregion

                #region | CREATE SMSs |

                if (!string.IsNullOrWhiteSpace(customerMobilePhone) && !string.IsNullOrWhiteSpace(customerFirstName)
                        && !string.IsNullOrWhiteSpace(customerLastName) && assemblerInfo != null)
                {
                    string customerSmsText = @"Sayın {0}, www.kalekilitesatis.com.tr sitemizden yaptığınız alışveriş için teşekkür ederiz. Montaj için anahtarcı bilgileri: {1}, Tel: {2}";

                    Entity ent = new Entity("new_sms");
                    ent["new_message"] = string.Format(customerSmsText, customerFullName, assemblerFullName, assemblerInfo.MobilePhoneNumber);
                    ent["new_phonenumber"] = customerMobilePhone;
                    ent["new_name"] = customerFirstName + " " + customerLastName + "|Montaj Talebi Mesajı";

                    service.Create(ent);
                }

                if (!string.IsNullOrWhiteSpace(assemblerInfo.MobilePhoneNumber) && !string.IsNullOrWhiteSpace(customerFirstName)
                        && !string.IsNullOrWhiteSpace(customerLastName) && assemblerInfo != null && userId != null)
                {
                    string customerSmsText = @"Sayın {0}, www.kalekilitesatis.com.tr sitemizden satışı yapılan ürünün montajı için müşteri bilgileri: {1} Tel: {2} şeklindedir. Müşterimizle irtibata geçmenizi rica ederiz.";

                    Entity ent = new Entity("new_sms");
                    ent["new_message"] = string.Format(customerSmsText, assemblerFullName, customerFullName, customerMobilePhone);
                    ent["new_phonenumber"] = assemblerInfo.MobilePhoneNumber;
                    ent["new_name"] = customerFirstName + " " + customerLastName + "|Montaj Talebi Mesajı";
                    ent["new_userid"] = userId;

                    service.Create(ent);
                }

                #endregion

                #region | CREATE NPS Survey |

                Entity entSurvey = new Entity("new_npssurvey");
                entSurvey["new_name"] = customerFullName + "|" + DateTime.Now.ToString("dd.MM.yyyy HH:mm");
                entSurvey["new_asseblyrequestid"] = entity.ToEntityReference();

                service.Create(entSurvey);

                #endregion
            }
            catch (Exception ex)
            {
                //LOG
                throw new InvalidPluginExecutionException(ex.Message + "->>>" + ex.StackTrace);
            }
            finally
            {
                if (sda != null)
                    sda.closeConnection();
            }
        }
예제 #5
0
        public List<EntityReference> GetTowns(string cityId)
        {
            List<EntityReference> returnValue = new List<EntityReference>();

            try
            {
                sda = new SqlDataAccess();
                sda.openConnection(Globals.ConnectionString);

                #region | SQL QUERY |

                string sqlQuery = @"SELECT
                                    t.new_townId AS Id
                                    ,t.new_name AS Name
                                    ,'new_town' AS LogicalName
                                FROM
                                new_town AS t (NOLOCK) WHERE t.new_cityId='{0}'";
                #endregion

                DataTable dt = sda.getDataTable(string.Format(sqlQuery, cityId));

                returnValue = dt.ToList<EntityReference>();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (sda != null)
                    sda.closeConnection();
            }

            return returnValue;
        }
예제 #6
0
        public List<EntityReference> GetCities()
        {
            List<EntityReference> returnValue = new List<EntityReference>();

            try
            {
                sda = new SqlDataAccess();
                sda.openConnection(Globals.ConnectionString);

                #region | SQL QUERY |

                string sqlQuery = @"SELECT
                                    c.new_cityId AS Id
                                    ,c.new_name AS Name
                                    ,'new_city' AS LogicalName
                                FROM
                                new_city AS c (NOLOCK)";
                #endregion

                DataTable dt = sda.getDataTable(sqlQuery);

                returnValue = dt.ToList<EntityReference>();

            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (sda != null)
                    sda.closeConnection();
            }

            return returnValue;
        }
예제 #7
0
        public MsCrmResultObj<List<Town>> GetTowns(string token, Guid cityId)
        {
            MsCrmResultObj<List<Town>> returnValue = new MsCrmResultObj<List<Town>>();

            LoginSession ls = new LoginSession();

            try
            {
                #region | CHECK SESSION |
                MsCrmResultObj<LoginSession> sessionResult = GetUserSession(token);

                if (!sessionResult.Success)
                {
                    returnValue.Result = sessionResult.Result;
                    return returnValue;
                }
                else
                {
                    ls = sessionResult.ReturnObject;
                }

                #endregion

                _sda = new SqlDataAccess();
                _sda.openConnection(Globals.ConnectionString);

                returnValue = LocationHelper.GetTowns(cityId, _sda);
            }
            catch (Exception ex)
            {
                returnValue.HasException = true;
                returnValue.Result = ex.Message;
            }
            finally
            {
                if (_sda != null)
                {
                    _sda.closeConnection();
                }
            }

            return returnValue;
        }
예제 #8
0
        public MsCrmResultObj<List<AssemblerInfo>> GetAssemblerList(string token, Guid cityId, Guid townId)
        {
            MsCrmResultObj<List<AssemblerInfo>> returnValue = new MsCrmResultObj<List<AssemblerInfo>>();

            LoginSession ls = new LoginSession();

            try
            {
                #region | CHECK SESSION |
                MsCrmResultObj<LoginSession> sessionResult = GetUserSession(token);

                if (!sessionResult.Success)
                {
                    returnValue.Result = sessionResult.Result;
                    return returnValue;
                }
                else
                {
                    ls = sessionResult.ReturnObject;
                }

                #endregion

                _sda = new SqlDataAccess();
                _sda.openConnection(Globals.ConnectionString);

                returnValue = AssemblyRequestHelper.GetAssemblerList(new Guid(Globals.DefaultPortalId), cityId, townId, _sda);
            }
            catch (Exception ex)
            {
                returnValue.HasException = true;
                returnValue.Result = ex.Message;
            }
            finally
            {
                if (_sda != null)
                {
                    _sda.closeConnection();
                }
            }

            return returnValue;
        }
예제 #9
0
        public static void CreateLogBySql(string applicationName, string functionName, string detail, string createdBy, string businessUnit, EventType eventType)
        {
            try
            {
                SqlDataAccess sda = new SqlDataAccess();
                sda.openConnection(Globals.ConnectionString);

                string sqlQuery = @"DECLARE @EventLogID uniqueidentifier
                                    SET @EventLogID=NEWID()

                                    INSERT
                                    INTO
	                                    new_eventlogBase
	                                    (new_eventlogId
	                                    ,CreatedOn
	                                    ,CreatedBy
	                                    ,ModifiedOn
	                                    ,ModifiedBy
	                                    ,OwnerId
	                                    ,OwningBusinessUnit
	                                    ,statecode
	                                    ,statuscode
                                    )
                                    VALUES
                                    (
	                                    @EventLogID
	                                    ,@CreatedOn
	                                    ,@CreatedBy
	                                    ,@CreatedOn
	                                    ,@CreatedBy
	                                    ,@CreatedBy
	                                    ,@BusinessUnit
	                                    ,0
	                                    ,1
                                    )

                                    INSERT
                                    INTO
	                                    new_eventlogExtensionBase
                                    (
	                                    new_eventlogId
	                                    ,new_name
	                                    ,new_applicationname
	                                    ,new_detail
	                                    ,new_eventtype
	                                    ,new_function
                                    )
                                    VALUES
                                    (
	                                    @EventLogID
	                                    ,@Title
	                                    ,@ApplicationName
	                                    ,@Detail
	                                    ,@EventType
	                                    ,@FunctionName
                                    )";

                string title           = string.Format("{0} - {1} - {2}", applicationName, functionName, DateTime.Now.ToString("dd.MM.yyyy HH:mm"));
                List <SqlParameter> li = new List <SqlParameter>();
                li.Add(new SqlParameter("@CreatedOn", DateTime.UtcNow));
                li.Add(new SqlParameter("@CreatedBy", new Guid(createdBy)));
                li.Add(new SqlParameter("@CreatedBy", new Guid(businessUnit)));
                li.Add(new SqlParameter("@Title", title));
                li.Add(new SqlParameter("@ApplicationName", applicationName));
                li.Add(new SqlParameter("@Detail", detail));
                li.Add(new SqlParameter("@EventType", (int)eventType));
                li.Add(new SqlParameter("@FunctionName", functionName));

                sda.ExecuteNonQuery(sqlQuery, li.ToArray());

                sda.closeConnection();
            }
            catch (Exception ex)
            {
            }
        }