예제 #1
0
        public CrmResponse <String> AccountRegister(AccountRegisterModel registerModel)
        {
            string _errormsg;
            CrmResponse <String> _response = new CrmResponse <string>();

            if (registerModel.Password.Equals(registerModel.RePassword))
            {
                var data = _accountData.AccountRegisterData(registerModel.FullName, registerModel.Email, registerModel.Password, out _errormsg);
                if (!_errormsg.Equals(""))
                {
                    _response.Message = _errormsg;
                    _response.Success = false;
                    _response.Data    = null;
                }
                else
                {
                    _response.Message = "";
                    _response.Success = true;
                    _response.Data    = data;
                }
            }
            else
            {
                _response.Message = "Password did not match";
                _response.Success = false;
                _response.Data    = null;
            }

            return(_response);
        }
예제 #2
0
        public CrmResponse AddNewJbi(ENTITIES.JBI jbi)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                JBI            newJbi = new JBI();
                Type           myType = newJbi.GetType();
                PropertyInfo[] props  = myType.GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    object jbiValue = jbi.GetType().GetProperty(prop.Name).GetValue(jbi);
                    newJbi.GetType().GetProperty(prop.Name).SetValue(newJbi, jbiValue);
                }
                _context.JBIs.Add(newJbi);
                _context.SaveChanges();
                jbi.Moneln = _context.JBIs.Max().Moneln;
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                response.desc = ex.Message;
            }

            return(response);
        }
예제 #3
0
        public CrmResponse DeleteJBI(int idJBI)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                JBI one = _context.JBIs.Where((x) => x.Moneln == idJBI).FirstOrDefault();
                if (one != null)
                {
                    _context.JBIs.Remove(one);
                    _context.SaveChanges();
                    response.rc    = 0;
                    response.title = "Delete one JBI success";
                }
                else
                {
                    response.rc    = 1;
                    response.title = "Id is not found";
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                response.desc = ex.Message;
            }

            return(response);
        }
예제 #4
0
        public CrmResponse <String> LoadUser(string uname)
        {
            //string _errormsg;
            CrmResponse <String> _response = new CrmResponse <String>();

            _response.Message = "";
            _response.Success = true;
            _response.Data    = "Jhon";

            return(_response);
        }
예제 #5
0
        public CrmResponse AddNewJbi(ENTITIES.JBI jbi)
        {
            CrmResponse response = new CrmResponse();

            using (DalJBI context = new DalJBI())
            {
                response = context.AddNewJbi(jbi);
            }


            return(response);
        }
예제 #6
0
        public CrmResponse UpdateJBI(ENTITIES.JBI jbi)
        {
            CrmResponse response = new CrmResponse();

            using (DalJBI context = new DalJBI())
            {
                response = context.UpdateJBI(jbi);
            }


            return(response);
        }
예제 #7
0
        public CrmResponse DeleteJBI(int idJBI)
        {
            CrmResponse response = new CrmResponse();

            using (DalJBI context = new DalJBI())
            {
                response = context.DeleteJBI(idJBI);
            }


            return(response);
        }
예제 #8
0
        public CrmResponse InsertActivity(ENTITIES.Activity newActivity)
        {
            CrmResponse response = new CrmResponse();

            using (DalActivity context = new DalActivity())
            {
                response = context.InsertNewActivity(newActivity);
                if (response.rc > -1)
                {
                    //insert lines to schedule email sending
                    response = context.ScheduleEmails(response.rc);
                }
            }


            return(response);
        }
예제 #9
0
        public CrmResponse DeleteJBI(int idJBI)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                using (var manager = new JBIManager())
                {
                    response = manager.DeleteJBI(idJBI);
                }
            }
            catch (Exception ex)
            {
                //-----------------------------------------------------------------------------adderror to db---------------------------------------------------------------------------------------------
                response.title = "Error in DeleteJBI function";
                response.body  = ex.Message;
                response.rc    = 99;
            }
            return(response);
        }
예제 #10
0
        public CrmResponse AddNewJbi([FromBody] JBI request)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                using (var manager = new JBIManager())
                {
                    response = manager.AddNewJbi(request);
                }
            }
            catch (Exception ex)
            {
                //-----------------------------------------------------------------------------adderror to db---------------------------------------------------------------------------------------------
                response.title = "Error in DeleteJBI function";
                response.body  = ex.Message;
                response.rc    = 99;
            }
            return(response);
        }
예제 #11
0
        public CrmResponse InsertActivity([FromBody] Activity activity)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                using (var manager = new ActivityManager())
                {
                    response = manager.InsertActivity(activity);
                }
            }
            catch (Exception ex)
            {
                //-----------------------------------------------------------------------------adderror to db---------------------------------------------------------------------------------------------
                response.title = "Error in InsertActivity function";
                response.body  = ex.Message;
                response.rc    = 99;
            }
            return(response);
        }
예제 #12
0
        public CrmResponse <AccountUserModel> AccountLogin(AccountLoginModel accountModel)
        {
            string _errormsg;
            CrmResponse <AccountUserModel> _response = new CrmResponse <AccountUserModel>();
            var data = _accountData.AccountLoginData(accountModel.UserName, accountModel.Password, out _errormsg);

            if (!_errormsg.Equals(""))
            {
                _response.Message = _errormsg;
                _response.Success = false;
                _response.Data    = null;
            }
            else
            {
                _response.Message = "";
                _response.Success = true;
                _response.Data    = new AccountUserModel {
                    FullName = data, Email = "", Token = "avb5t-6tyui-re34d"
                };
            }
            return(_response);
        }
예제 #13
0
        public CrmResponse UpdateJBI(ENTITIES.JBI jbi)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                JBI updatedRow = _context.JBIs.Where((x) => x.Moneln == jbi.Moneln).FirstOrDefault();
                if (updatedRow != null)
                {
                    Type           myType = updatedRow.GetType();
                    PropertyInfo[] props  = myType.GetProperties();
                    foreach (PropertyInfo prop in props)
                    {
                        //object oneKey = prop.Name;
                        //object onevalue = prop.GetValue(updatedRow, new object[] { });

                        object jbiValue = jbi.GetType().GetProperty(prop.Name).GetValue(jbi);
                        updatedRow.GetType().GetProperty(prop.Name).SetValue(updatedRow, jbiValue);
                    }

                    _context.SaveChanges();
                }
                else
                {
                    response.rc    = 1;
                    response.title = "Id is not found";
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                response.desc = ex.Message;
            }

            return(response);
        }
예제 #14
0
        public CrmResponse InsertNewActivity(ENTITIES.Activity activity)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                Activity       newActivity = new Activity();
                Type           myType      = newActivity.GetType();
                PropertyInfo[] props       = myType.GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    object temp = activity.GetType().GetProperty(prop.Name);
                    if (!(temp is null))
                    {
                        object activityValue = activity.GetType().GetProperty(prop.Name).GetValue(activity);
                        newActivity.GetType().GetProperty(prop.Name).SetValue(newActivity, activityValue);
                    }
                }

                //buttons
                newActivity.Button1    = activity.Buttons[0];
                newActivity.Button2    = activity.Buttons[1];
                newActivity.Button3    = activity.Buttons[2];
                newActivity.InsertDate = DateTime.Now;

                Activity act = _context.Activities.Add(newActivity);
                _context.SaveChanges();
                int activityId = act.ActivityId;

                //textBoxes
                List <TextBox> textBoxes = new List <TextBox>();
                foreach (var item in activity.TextBoxList)
                {
                    TextBox textBox = new TextBox
                    {
                        ActivityId = activityId,
                        Bold       = item.Bold,
                        Color      = item.Color,
                        FontSize   = item.FontSize,
                        Text       = item.Text,
                        TextBoxId  = item.BoxId
                    };
                    textBoxes.Add(textBox);
                }
                _context.TextBoxes.AddRange(textBoxes);
                _context.SaveChanges();

                //JBI
                List <ActivityJBI> JBIs = new List <ActivityJBI>();
                foreach (var item in activity.JBIlist)
                {
                    ActivityJBI jbi = new ActivityJBI
                    {
                        ActivityId = activityId,
                        JBIId      = item.Moneln
                    };
                    JBIs.Add(jbi);
                }
                _context.ActivityJBIs.AddRange(JBIs);
                _context.SaveChanges();
                response.rc = activityId;
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                response.desc = ex.Message;
                response.rc   = -1;
            }

            return(response);
        }
예제 #15
0
        public CrmResponse ScheduleEmails(int activityId)
        {
            CrmResponse response = new CrmResponse();

            try
            {
                Activity activity = _context.Activities.Where((x) => x.ActivityId == activityId).FirstOrDefault();
                if (activity is null)
                {
                    throw new Exception("Activity is not exist in Activity table");
                }
                bool isScheduleActivity         = activity.SendingType == 0 ? false : true;
                List <EmailsQueue> RowsToInsert = new List <EmailsQueue>();
                List <ActivityJBI> JBIs         = _context.ActivityJBIs.Where((x) => x.ActivityId == activityId).ToList();
                if (JBIs is null)
                {
                    throw new Exception("JBI list of activity: " + activityId + " is null");
                }
                DateTime now = DateTime.Now; //take snap of time now

                if (isScheduleActivity)
                {
                    int periodBetweenSending = (int)activity.PeriodBetweenSending;
                    foreach (ActivityJBI item in JBIs)
                    {
                        for (int i = 0; i < activity.MessagesPerPerson; i++)
                        {
                            EmailsQueue row = new EmailsQueue
                            {
                                ActivityId  = activityId,
                                ActivityJBI = item.JBIId,
                                SendDt      = now,
                                Done        = false
                            };
                            RowsToInsert.Add(row);

                            //add time to now
                            switch (activity.PeriodBetweenSendingType)
                            {
                            case 0:     //minutes
                                now = now.AddMinutes(periodBetweenSending);
                                break;

                            case 1:     //hours
                                now = now.AddHours(periodBetweenSending);
                                break;

                            case 2:     //days
                                now = now.AddDays(periodBetweenSending);
                                break;

                            case 3:     //weeks
                                now = now.AddDays(periodBetweenSending * 7);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (ActivityJBI item in JBIs)
                    {
                        EmailsQueue row = new EmailsQueue
                        {
                            ActivityId  = activityId,
                            ActivityJBI = item.JBIId,
                            SendDt      = now,
                            Done        = false
                        };

                        RowsToInsert.Add(row);
                    }
                }
                _context.EmailsQueues.AddRange(RowsToInsert);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                response.desc = ex.Message;
                response.rc   = -1;
            }
            return(response);
        }