Exemplo n.º 1
0
        public async Task <IHttpActionResult> PostExposeBook(int id)
        {
            ViewModels.BookExpose dto = new ViewModels.BookExpose()
            {
                BookId          = id,
                AppNotification = true,
                CustomerId      = 1,
                Email           = true,
                SMS             = true,
            };
            var result = await unitOfWork.BookRepository.ExposeBook(dto);

            if (result)
            {
                var saveResult = await unitOfWork.SaveAsync();

                if (saveResult.Code != HttpStatusCode.OK)
                {
                    return(saveResult);
                }


                return(Ok(id));
            }

            else
            {
                return(InternalServerError());
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PostExposeBook(ViewModels.BookExpose dto)
        {
            var result = await unitOfWork.BookRepository.ExposeBook(dto);

            if (result)
            {
                var saveResult = await unitOfWork.SaveAsync();

                if (saveResult.Code != HttpStatusCode.OK)
                {
                    return(saveResult);
                }


                return(Ok(dto));
            }

            else
            {
                return(InternalServerError());
            }
        }
Exemplo n.º 3
0
        public async Task <bool> ExposeBook(ViewModels.BookExpose dto)
        {
            try
            {
                var book = await dbSet.FirstOrDefaultAsync(q => q.Id == dto.BookId);

                book.DatePublished = DateTime.Now;

                var applicables = this.context.ViewBookApplicableEmployees.Where(q => q.BookId == dto.BookId).Select(q => new { q.EmployeeId, q.Name, q.Title, q.Type }).ToList();
                foreach (var x in applicables)
                {
                    var _message = "Dear " + x.Name + ",<br/>"
                                   + "You have new " + x.Type + " in your library."
                                   + "<br/>"
                                   + "<strong>" + x.Title + "</strong>";
                    var notification = new Models.Notification()
                    {
                        App        = dto.AppNotification,
                        CustomerId = dto.CustomerId,
                        DateSent   = DateTime.Now,
                        Email      = dto.Email,
                        ModuleId   = 2,
                        SMS        = dto.SMS,
                        UserId     = x.EmployeeId,
                        TypeId     = 98,
                        Message    = _message,
                    };
                    this.context.Notifications.Add(notification);
                }
                //send notification


                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        //magu3-1
        public async Task <bool> ExposeBook(ViewModels.BookExpose dto)
        {
            try
            {
                List <string> names   = new List <string>();
                List <string> numbers = new List <string>();
                List <string> sms     = new List <string>();
                var           book    = await dbSet.FirstOrDefaultAsync(q => q.Id == dto.BookId);

                book.DatePublished = DateTime.Now;

                var applicables = this.context.ViewBookApplicableEmployees.Where(q => q.BookId == dto.BookId).Select(q => new { q.EmployeeId, q.Name, q.Title, q.Type, q.Mobile }).ToList();

                string _issue = "";
                if (book.Issue != null)
                {
                    try
                    {
                        _issue = book.Issue.ToString();
                    }
                    catch (Exception _ex)
                    {
                    }
                }

                foreach (var x in applicables)
                {
                    var datesent = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                    var _message = "Dear " + x.Name + ",<br/>"
                                   + "A new " + x.Type + " added to your e-library: " + x.Title
                                   + "<br/>"
                                   + "Please access your WebPocket account to see more details."
                                   + "<br/>"
                                   + "Date Sent: " + datesent;

                    var _sms = "Dear " + x.Name + "," + "\n\n"
                               + "A new " + x.Type + " added to your e-library: "
                               + "\n"
                               + x.Title
                               + "\n"
                               + (!string.IsNullOrEmpty(_issue)?"Issue: " + _issue + "\n" : "")
                               + (!string.IsNullOrEmpty(book.Edition) ? "Revision: " + book.Edition + "\n" : "")
                               + "Please access your WebPocket account to see more details."
                               + "\n\n"
                               + "Date Sent: " + datesent;

                    // var text = "A new item added to your e-library: " + "\n\n" + $scope.dg_selected.Title + "\n\n" + "Please access your Crew Pocket account to see more details."
                    //          + "\n" + "Date Sent: " + moment(new Date()).format('MM-DD-YYYY HH:mm');


                    var notification = new Models.Notification()
                    {
                        App        = dto.AppNotification,
                        CustomerId = dto.CustomerId,
                        DateSent   = DateTime.Now,
                        Email      = dto.Email,
                        ModuleId   = 2,
                        SMS        = dto.SMS,
                        UserId     = x.EmployeeId,
                        TypeId     = 98,
                        Message    = _message,
                    };
                    this.context.Notifications.Add(notification);

                    if (!string.IsNullOrEmpty(x.Mobile))
                    {
                        names.Add(x.Name);
                        numbers.Add(x.Mobile);
                        sms.Add(_sms);
                    }
                }
                //send notification
                new Thread(() =>
                {
                    try
                    {
                        int c     = 0;
                        Magfa mgf = new Magfa();
                        foreach (var m in numbers)
                        {
                            var txt = sms[c];
                            var res = mgf.enqueue(1, m, txt);
                            c++;
                        }
                    }
                    catch (Exception eex)
                    {
                        int i = 0;
                    }
                }).Start();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }