Example #1
0
        public JsonResult Send(SmsOption model)
        {
            Response      response;
            List <string> personelNumber;

            try
            {
                var date = DateUtility.GetDateTime(model.persianDate);

                if (!string.IsNullOrEmpty(model.branchId))
                {
                    using (var db = new KiaGalleryContext())
                    {
                        var        branchIdList = model.branchId.Split();
                        List <int> myInts       = branchIdList.Select(int.Parse).ToList();
                        personelNumber = db.User.Where(y => myInts.Contains(y.BranchId.Value) && y.PhoneNumber != null && y.PhoneNumber != "").Select(y => y.PhoneNumber).ToList();
                    }
                    Task.Factory.StartNew(() =>
                    {
                        NikSmsWebServiceClient.SendSmsNik(model.text, personelNumber);
                    });
                }
                if (model.phoneNumber != null && model.phoneNumber != "" && !model.phoneNumber.Contains('-'))
                {
                    Task.Factory.StartNew(() =>
                    {
                        NikSmsWebServiceClient.SendSmsNik(model.text, model.phoneNumber);
                    });
                }
                if (model.phoneNumber != null && model.phoneNumber != "" && model.phoneNumber.Contains('-'))
                {
                    var numberList = model.phoneNumber.Split('-');
                    var numbers    = new List <string>();
                    numbers.AddRange(numberList);
                    Task.Factory.StartNew(() =>
                    {
                        NikSmsWebServiceClient.SendSmsNik(model.text, numbers);
                    });
                }

                response = new Response()
                {
                    status  = 200,
                    message = "Done",
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public JsonResult Save(SmsOption model)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    if (model.id > 0 && model.id != null)
                    {
                        var entity = db.Sms.Single(x => x.Id == model.id);
                        entity.Text              = model.text;
                        entity.DayOfMonth        = model.dayOfMonth;
                        entity.DayOfWeek         = model.dayOfWeek;
                        entity.SendingTimeMethod = model.sendingTimeMethod;
                        entity.Sent              = false;
                        entity.DestinationNumber = model.phoneNumber;
                        entity.UserId            = model.userId;
                        entity.BranchId          = model.branchId;
                        entity.SendingDate       = DateUtility.GetDateTime(model.persianDate).Value;
                        entity.TimeTotalMinutes  = (int)TimeSpan.Parse(model.time).TotalMinutes;
                        entity.Time              = model.time;
                        entity.CreateUserId      = GetAuthenticatedUserId();
                        entity.ModifyUserId      = GetAuthenticatedUserId();
                    }
                    else
                    {
                        var entity = new Sms()
                        {
                            Text              = model.text,
                            DayOfMonth        = model.dayOfMonth,
                            DayOfWeek         = model.dayOfWeek,
                            SendingTimeMethod = model.sendingTimeMethod,
                            Sent              = false,
                            DestinationNumber = model.phoneNumber,
                            UserId            = model.userId,
                            BranchId          = model.branchId,
                            SendingDate       = DateUtility.GetDateTime(model.persianDate).Value,
                            TimeTotalMinutes  = (int)TimeSpan.Parse(model.time).TotalMinutes,
                            Time              = model.time,
                            CreateDate        = DateTime.Now.Date,
                            ModifyDate        = DateTime.Now.Date,
                            CreateUserId      = GetAuthenticatedUserId(),
                            ModifyUserId      = GetAuthenticatedUserId(),
                        };
                        db.Sms.Add(entity);
                    }
                    db.SaveChanges();
                }
                response = new Response()
                {
                    status  = 200,
                    message = "پیام با موفقیت ذخیره شد.",
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }