示例#1
0
        public List <Model.ViewModel.Error> SaveChanges(string Language)
        {
            // use this function only to save main record
            List <DbEntityEntry> entries = null;
            var errors = HrUnitOfWork.SaveChanges(Language, out entries);

            if (errors.Count > 0)
            {
                return(errors);
            }

            // now send notifications
            var notifications = entries.Where(e => e.Entity.ToString() == "Model.Domain.Notifications.Notification").Select(e => e.Entity);

            if (notifications.Count() > 0) // found notifications
            {
                foreach (var entity in notifications)
                {
                    var notification = (Model.Domain.Notifications.Notification)entity;
                    HangFireJobs.SendNotication(notification, notification.Condition, HrUnitOfWork.NotificationRepository);
                }
            }

            return(errors);
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IBackgroundJobClient backgroundJobs)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "KaznituLab v1"));
            }
            else
            {
                app.UseExceptionHandler(a => a.Run(async context =>
                {
                    var exceptionHandlerPathFeature = context.Features.Get <IExceptionHandlerPathFeature>();
                    var exception = exceptionHandlerPathFeature.Error;

                    await context.Response.WriteAsJsonAsync(new { error = exception.Message });
                }));
                app.UseHsts();
            }
            app.UseHangfireDashboard();
            app.UseHangfireServer();
            HangFireJobs.AddJobs();
            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors("CorsPolicy");
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        public ActionResult ExtendContract(int Id, int Period, bool Enable, bool OnStopError, bool Invoke)
        {
            string msg = "Enabled";

            if (Enable)
            {
                try
                {
                    int UNHour, UNMinute;
                    DateTimeServices.GetTimeUniversal(9, 0, User.Identity.GetTimeZone(), out UNHour, out UNMinute);
                    RecurringJob.AddOrUpdate(Id.ToString(), () => HangFireJobs.ExtendContract(Language), Cron.Daily(UNHour, UNMinute));
                }
                catch
                {
                    if (OnStopError)
                    {
                        RecurringJob.RemoveIfExists(Id.ToString());
                    }
                }


                if (!Invoke)
                {
                    RecurringJob.Trigger(Id.ToString());
                    var model = _hrUnitOfWork.Repository <SchedualTask>().Where(a => a.EventId == Id).FirstOrDefault();
                    UpdateTimeofTask(model);
                }
            }
            else
            {
                msg = "Disabled";
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            LogManager.Configuration.Variables["conString"] = Configuration.GetConnectionString("DefaultConnection");

            app.UseCors(MyAllowSpecificOrigins);

            // app.UseHttpsRedirection();
            if (env.IsProduction())
            {
                app.UseHttpsRedirection();
            }
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            //this call placement is important
            bool isDashboardReadOnly = Configuration.GetSection("Hangfiredashboard").GetValue <bool>("IsReadOnly");

            if (Debugger.IsAttached)
            {
                isDashboardReadOnly = false;
            }
            var options = new DashboardOptions
            {
                IsReadOnlyFunc = (x) => isDashboardReadOnly,
                Authorization  = new[] { new CustomAuthorizationFilter() }
            };

            app.UseHangfireDashboard("/hangfiredashboard", options);
            var hangfire = new HangFireJobs();

            BackgroundJob.Enqueue(() => Console.WriteLine("Starting Hangfire!"));
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        public ActionResult AddNotify(int Id, int Period, bool Enable, bool OnStopError, bool Invoke)
        {
            string msg = "Enabled";

            if (Enable)
            {
                EmailAccount ea = _hrUnitOfWork.Repository <EmailAccount>().FirstOrDefault();

                RecurringJob.AddOrUpdate(Id.ToString(), () => HangFireJobs.ReadNotifications(User.Identity.GetDefaultCompany(), User.Identity.GetEmpId(), User.Identity.GetLanguage()), Cron.MinuteInterval(Period));


                if (!Invoke)
                {
                    var model = _hrUnitOfWork.Repository <SchedualTask>().Where(a => a.EventId == Id).FirstOrDefault();
                    UpdateTimeofTask(model);
                }
            }
            else
            {
                msg = "Disabled";
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
        Notification AddNotification(NotifyCondition condition, string Id, int?EmpId)
        {
            var notification = new Notification
            {
                CompanyId    = company,
                ConditionId  = condition.Id,
                CreationTime = DateTime.Now,
                SourceId     = Id,
                Message      = MessageMerge(condition.EncodedMsg.Replace("&nbsp;", " ").Replace("&lt;", "<").Replace("&gt;", ">")),
                Subject      = condition.Subject,
                EmpId        = Identity.GetEmpId(),
                RefEmpId     = EmpId
            };

            int[] employees = notification.RefEmpId == null ? new int[] { } : new int[] { notification.RefEmpId.Value };
            IList <HangFireJobs.UserView> users = HangFireJobs.GetUsers(condition.Users, employees);

            foreach (var u in users.Where(a => a.WebNotify))
            {
                HrUnitOfWork.NotificationRepository.Add(new WebMobLog
                {
                    MarkAsRead = false,
                    Message    = notification.Message,
                    Notificat  = notification,
                    SentTime   = DateTime.Now,
                    SentToUser = u.Name,
                    Subject    = notification.Subject,
                    CompanyId  = company
                });
            }
            HrUnitOfWork.NotificationRepository.Add(notification);

            // Send it now
            HangFireJobs.SendNotication(notification, condition, HrUnitOfWork.NotificationRepository);

            return(notification);
        }