コード例 #1
0
        public static IQueryable <RecordModel> GetRecords(CheckInContext context)
        {
            AutoConfirm(context);
            var records = context.UserCheckInInfo.Join(context.UserInfo, x => x.UserID, x => x.UserID, (x, y) => new
            {
                x = x,
                y = y
            }).Join(context.DepartmentInfo, x => x.y.DepartmentID, x => x.DepartmentID, (x, y) => (new RecordModel
            {
                CheckInID = x.x.CheckInID,
                EmployeeID = x.y.EmployeeID,
                Name = x.y.Name,
                CheckInTime = x.x.CheckInTime,
                CheckOutTime = x.x.CheckOutTime,
                OriCheckInTime = x.x.OriCheckInTime,
                OriCheckOutTime = x.x.OriCheckOutTime,
                Reason1 = x.x.Reason1,
                Reason2 = x.x.Reason2,
                HasCheckOut = x.x.HasCheckOut,
                DepartmentID = x.y.DepartmentID,
                DepartmentName = y.DepartmentName,
                IsNormal = x.x.HasConfirmed
            }));

            return(records);
        }
コード例 #2
0
        private static void AutoConfirm(CheckInContext context)
        {
            var records = context.UserCheckInInfo.Where(x => x.HasConfirmed == false);

            foreach (var record in records)
            {
                if (record.HasCheckOut == true && record.CheckInTime == record.OriCheckInTime && record.CheckOutTime == record.OriCheckOutTime && record.CheckOutTime - record.CheckInTime < new TimeSpan(12, 0, 0) && record.CheckOutTime - record.CheckInTime > new TimeSpan(8, 0, 0))
                {
                    record.HasConfirmed = true;
                }
            }
            context.SaveChanges();
        }
コード例 #3
0
        public ActionResult Update(CheckInUpdateModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var language   = LanguageContext.GetLanguage(languageId);
                    var user       = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var checkIn = CheckInContext.GetDetail(dataContext, model.Id);
                    if (checkIn == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(checkIn.MapItem.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "CheckIn", new { id = checkIn.MapItemId }));
                    }

                    CheckInContext.Validate(dataContext, model, ModelState);
                    if (ModelState.IsValid)
                    {
                        var newItemId = CheckInContext.Update(dataContext, checkIn, model, user, language);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, CheckInRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "CheckIn", new { id = model.MapItemId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, CheckInRes.ERROR_UPDATE);
                        }
                    }
                    model.FillCodeLists(dataContext, checkIn.MapItem);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CheckInController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #4
0
 public IHttpActionResult CheckIn(CreateCheckInModel model)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             var session = GetSession();
             if (session == null)
             {
                 return(Content(HttpStatusCode.Unauthorized, SESSION_INVALID_MESSAGE));
             }
             var userSession = AclUserContext.GetUserSession(dataContext, session);
             if (userSession == null)
             {
                 return(Content(HttpStatusCode.Unauthorized, SESSION_INVALID_MESSAGE));
             }
             var mapItem = MapItemContext.GetDetail(dataContext, model.MapItemId);
             if (mapItem == null)
             {
                 return(Content(HttpStatusCode.NotFound, NOT_FOUND_MESSAGE));
             }
             if (userSession.AclUser.CanViewTerritory(mapItem.Territory) == false)
             {
                 return(Content(HttpStatusCode.Forbidden, FORBIDDEN_MESSAGE));
             }
             Questionnaire questionnaire = null;
             if (model.QuestionnaireId.HasValue)
             {
                 questionnaire = QuestionnaireContext.GetDetail(dataContext, model.QuestionnaireId.Value);
             }
             if (model.IsValid(dataContext, questionnaire) == false)
             {
                 return(Content(HttpStatusCode.BadRequest, BAD_REQUEST_MESSAGE));
             }
             var updateModel = new CheckInUpdateModel(model, questionnaire);
             var pointId     = CheckInContext.Update(dataContext, null, updateModel, userSession.AclUser, null);
             if (pointId == null)
             {
                 return(Content(HttpStatusCode.InternalServerError, FAILED_MESSAGE));
             }
             return(Ok(pointId.Value.ToString()));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }
コード例 #5
0
        // GET: CheckIn/id
        public ActionResult Index(int id, CheckInFilter filter, int?page)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var language   = LanguageContext.GetLanguage(languageId);
                    var user       = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var mapItem = MapItemContext.GetDetail(dataContext, id);
                    if (mapItem == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanViewTerritory(mapItem.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    filter.PrepareFilter();
                    filter.MapItemId = mapItem.Id;
                    int pageIndex     = page ?? 0;
                    var itemList      = CheckInContext.GetList(dataContext, filter, pageIndex);
                    var itemListModel = new CheckInListModel(itemList, pageIndex, language);
                    var model         = new CheckInPageModel(itemListModel, filter, mapItem);
                    model.CanUpdate = user.CanUpdateTerritory(mapItem.Territory);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CheckInController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #6
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var checkIn = CheckInContext.GetDetail(dataContext, id);
                    if (checkIn == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(checkIn.MapItem.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "CheckIn", new { id = checkIn.MapItemId }));
                    }

                    var isSuccess = CheckInContext.Delete(dataContext, checkIn, user);
                    if (isSuccess)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, CheckInRes.SUCCESS_DELETE);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, CheckInRes.ERROR_DELETE);
                    }
                    return(RedirectToAction("Index", "CheckIn", new { id = checkIn.MapItemId }));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CheckInController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #7
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            CheckInContext db = new CheckInContext();

            while (!cancellationToken.IsCancellationRequested)
            {
                Trace.TraceInformation("Working");

                DbSqlQuery <UserCheckIn> query = db.UserCheckIns.SqlQuery("SELECT * FROM dbo.UserCheckIns WHERE returnTime <= @p0", DateTime.UtcNow);

                List <UserCheckIn> expiredCheckIns = query.ToList();

                foreach (UserCheckIn checkIn in expiredCheckIns)
                {
                    sendMissingEmail(checkIn);
                    db.UserCheckIns.Remove(checkIn);
                    db.SaveChanges();
                }

                await Task.Delay(checkEvery * 1000);
            }
        }
コード例 #8
0
 // GET: CheckIn/Detail/id
 public ActionResult Detail(int id)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             var language   = LanguageContext.GetLanguage(languageId);
             var user       = AclUserContext.GetDetail(dataContext, User.Identity.Name);
             if (user == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var checkIn = CheckInContext.GetDetail(dataContext, id);
             if (checkIn == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                 return(RedirectToAction("Index", "Home"));
             }
             if (user.CanViewTerritory(checkIn.MapItem.Territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new CheckInDetailModel(checkIn, language);
             model.CanUpdate = user.CanUpdateTerritory(checkIn.MapItem.Territory);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "CheckInController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
コード例 #9
0
        public static IQueryable <RecordModel> GetAbnormalRecords(CheckInContext context)
        {
            AutoConfirm(context);
            var records = context.UserCheckInInfo.Where(x => x.HasConfirmed == false).Join(context.UserInfo, x => x.UserID, x => x.UserID, (x, y) => new
            {
                x = x,
                y = y
            }).Join(context.DepartmentInfo, x => x.y.DepartmentID, x => x.DepartmentID, (x, y) => (new RecordModel
            {
                CheckInID = x.x.CheckInID,
                EmployeeID = x.y.EmployeeID,
                Name = x.y.Name,
                CheckInTime = x.x.CheckInTime,
                CheckOutTime = x.x.CheckOutTime,
                OriCheckInTime = x.x.OriCheckInTime,
                OriCheckOutTime = x.x.OriCheckOutTime,
                Reason1 = x.x.Reason1,
                Reason2 = x.x.Reason2,
                HasCheckOut = x.x.HasCheckOut,
                DepartmentName = y.DepartmentName
            })).Where(x => (x.HasCheckOut == false && x.CheckInTime.Date != DateTime.Now.Date) || x.CheckInTime != x.OriCheckInTime || x.CheckOutTime != x.OriCheckOutTime || (x.HasCheckOut && (x.CheckOutTime - x.CheckInTime > new TimeSpan(12, 0, 0) || x.CheckOutTime - x.CheckInTime < new TimeSpan(8, 0, 0)))).OrderBy(x => x.CheckInID);

            return(records);
        }
コード例 #10
0
ファイル: HomeController.cs プロジェクト: kkwpsv/CheckIn
 public HomeController(CheckInContext context) : base(context)
 {
 }
コード例 #11
0
ファイル: RecordController.cs プロジェクト: kkwpsv/CheckIn
 public RecordController(CheckInContext context) : base(context)
 {
 }
コード例 #12
0
ファイル: LocationController.cs プロジェクト: kkwpsv/CheckIn
 public LocationController(CheckInContext context) : base(context)
 {
 }
コード例 #13
0
 public AppointmentRepository(CheckInContext context) : base(context)
 {
     this.context = context;
     appointments = context.Set <Appointment> ();
 }
コード例 #14
0
ファイル: TelephoneController.cs プロジェクト: kkwpsv/CheckIn
 public TelephoneController(CheckInContext context)
 {
     this.context = context;
 }
コード例 #15
0
 public ControllerWithAuthorize(CheckInContext context)
 {
     this.context = context;
 }
コード例 #16
0
 public NoticeController(CheckInContext context) : base(context)
 {
 }
コード例 #17
0
 public DepartmentController(CheckInContext context)
 {
     this.context = context;
 }
コード例 #18
0
 public UsersController(CheckInContext context) : base(context)
 {
 }
コード例 #19
0
 public NoticeController(CheckInContext context)
 {
     this.context = context;
 }
コード例 #20
0
ファイル: UserController.cs プロジェクト: kkwpsv/CheckIn
 public UserController(CheckInContext context)
 {
     this.context = context;
 }
コード例 #21
0
ファイル: LocationController.cs プロジェクト: kkwpsv/CheckIn
 public LocationController(CheckInContext context)
 {
     this.context = context;
 }
コード例 #22
0
ファイル: ReportController.cs プロジェクト: kkwpsv/CheckIn
 public ReportController(CheckInContext context)
 {
     this.context = context;
 }
コード例 #23
0
ファイル: EFRepository.cs プロジェクト: lizrt/CheckInWorkFlow
 public EFRepository(CheckInContext context)
 {
     this.context = context;
     entities     = context.Set <T> ();
 }
コード例 #24
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, CheckInContext dbContext)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseStatusCodePages();
            }

            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseMvc();

            DbInitializer.Initialize(dbContext);
        }
コード例 #25
0
 public AbnormalRecordController(CheckInContext context) : base(context)
 {
 }