示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SchedulingDbContext schedulingDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHttpsRedirection();
                app.UseHsts();
            }

            app.UseCors("AllowAll");

            schedulingDbContext.EnsureDbSeeded();

            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseMvc();
        }
        public static Boolean ManageEmpSchedules(List <EmpSchedules> schedules, SchedulingDbContext schedulingDbContext)
        {
            //Transaction Begin
            using (var dbContextTxn = schedulingDbContext.Database.BeginTransaction())
            {
                try
                {
                    foreach (EmpSchedules emp in schedules)
                    {
                        if (emp.TxnType == "Insert")
                        {
                            AddEmpSchedules(schedulingDbContext, emp);
                        }
                        else if (emp.TxnType == "Update")
                        {
                            UpdateEmpSchedules(schedulingDbContext, emp);
                        }
                    }

                    //Commit Transaction
                    dbContextTxn.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Rollback all transaction if exception occured
                    dbContextTxn.Rollback();
                    throw ex;
                }
            }
        }
示例#3
0
        public string Put()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();
            SchedulingDbContext         schDbContext = new SchedulingDbContext(connString);
            string reqType = this.ReadQueryStringData("reqType");
            string str     = this.ReadPostData();

            try
            {
                #region Update Shifts (Manage Shifts)
                if (reqType == "UpdateShift")
                {
                    ShiftsMasterModel shiftData = DanpheJSONConvert.DeserializeObject <ShiftsMasterModel>(str);
                    shiftData.ModifiedOn = System.DateTime.Now;
                    schDbContext.ShiftsMaster.Attach(shiftData);
                    schDbContext.Entry(shiftData).State = EntityState.Modified;
                    schDbContext.Entry(shiftData).Property(x => x.CreatedOn).IsModified = false;
                    schDbContext.Entry(shiftData).Property(x => x.CreatedBy).IsModified = false;
                    schDbContext.SaveChanges();
                    responseData.Status  = "OK";
                    responseData.Results = shiftData;
                }
                #endregion
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }

            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
示例#4
0
            public Validator(SchedulingDbContext db)
            {
                RuleFor(x => x.TemplateId)
                .EntityMustExist <Command, Guid, Template>(db);

                RuleFor(x => x.Order)
                .Must(BeValidOrdinalPosition);
            }
示例#5
0
            public Validation(SchedulingDbContext db)
            {
                RuleFor(x => x.StationId)
                .EntityMustExist <Command, Guid, Station>(db);

                RuleFor(x => x.Start)
                .Must((command, time) => time < command.End);
            }
示例#6
0
        public static void SetupTestRun(TestContext testContext)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <SchedulingDbContext, Configuration>());

            using (SchedulingDbContext db = SchedulingDbContext.Create())
            {
                db.Database.Initialize(true);
            }
        }
        public void Init()
        {
            var options = new DbContextOptionsBuilder <SchedulingDbContext>()
                          .UseInMemoryDatabase(databaseName: "Scheduling_Context_Mock")
                          .Options;

            _schedulingDbContext = new SchedulingDbContext(options);

            _schedulingDbContext.EnsureDbSeeded();
            _placeRepository = new PlaceRepository(_schedulingDbContext);
        }
 public static void AddEmpSchedules(SchedulingDbContext schDBContext, EmpSchedules schedules)
 {
     try
     {
         schDBContext.EmpSchedules.Add(schedules);
         schDBContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#9
0
        /// <summary>
        /// Get all the Facilities
        /// </summary>
        /// <returns>All Facilities</returns>
        public List <FacilityModel> GetFacilities()
        {
            //TODO this should have Access Control based on who is logged in

            // Get teh DB context, this would normally be injected in.
            SchedulingDbContext scheduleContext = new SchedulingDbContext();
            //Simply query all Factilites
            List <FacilityDataModel> all = scheduleContext.Facilities.ToList();
            // Map the Data Objects back to the Models
            List <FacilityModel> models = AutoMapper.Mapper.Map <List <FacilityDataModel>, List <FacilityModel> >(all);

            return(models);
        }
 public static void UpdateEmpSchedules(SchedulingDbContext schDBContext, EmpSchedules schedules)
 {
     try
     {
         schDBContext.EmpSchedules.Attach(schedules);
         schDBContext.Entry(schedules).Property(x => x.IsWorkingDay).IsModified = true;
         schDBContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public static void AddShiftMaster(SchedulingDbContext schDbContext, ShiftsMasterModel shift)
 {
     try
     {
         shift.CreatedOn = System.DateTime.Now;
         schDbContext.ShiftsMaster.Add(shift);
         schDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public static void AddEmpShiftMap(SchedulingDbContext schDbContext, EmployeeShiftMap shiftMap)
 {
     try
     {
         shiftMap.CreatedOn = System.DateTime.Now;
         schDbContext.EmpShiftMAP.Add(shiftMap);
         schDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public static void UpdateEmpShiftMap(SchedulingDbContext schDbContext, EmployeeShiftMap shiftMap)
 {
     try
     {
         shiftMap.ModifiedOn = System.DateTime.Now;
         schDbContext.EmpShiftMAP.Attach(shiftMap);
         schDbContext.Entry(shiftMap).State = EntityState.Modified;
         schDbContext.Entry(shiftMap).Property(x => x.CreatedOn).IsModified = false;
         schDbContext.Entry(shiftMap).Property(x => x.CreatedBy).IsModified = false;
         schDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 //here im updating shift master from Manage working hours txn .. as i need following fields(shiftname,starttime,endtime,totalhrs) to get updated, so i have bought only that much content here...
 #region Update Shift Master
 public static void UpdateShiftMaster(SchedulingDbContext schDbContext, ShiftsMasterModel shift)
 {
     try
     {
         shift.ModifiedOn = System.DateTime.Now;
         schDbContext.ShiftsMaster.Attach(shift);
         schDbContext.Entry(shift).Property(x => x.ShiftName).IsModified = true;
         schDbContext.Entry(shift).Property(x => x.StartTime).IsModified = true;
         schDbContext.Entry(shift).Property(x => x.EndTime).IsModified   = true;
         schDbContext.Entry(shift).Property(x => x.TotalHrs).IsModified  = true;
         schDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static Boolean WorkingHrsTxn(WorkingHoursTxnVM workHrsTxn, SchedulingDbContext schedulingDbContext)
        {
            using (var dbContextTxn = schedulingDbContext.Database.BeginTransaction())
            {
                try
                {
                    //currently we are not adding or updating shift at employee level thats why commented out below code. --- ramavtar 30May'18
                    //foreach (ShiftsMasterModel s in workHrsTxn.Shifts)
                    //{
                    //    if (s.ShiftId > 0)
                    //        UpdateShiftMaster(schedulingDbContext, s);
                    //    else if (s.ShiftId == 0)
                    //        AddShiftMaster(schedulingDbContext, s);
                    //}

                    //assigning newly addded shiftid to map-data
                    var index = 0;
                    foreach (EmployeeShiftMap m in workHrsTxn.Maps)
                    {
                        if (m.EmployeeShiftMapId > 0)
                        {
                            UpdateEmpShiftMap(schedulingDbContext, m);
                        }
                        else if (m.EmployeeShiftMapId == 0)
                        {
                            m.ShiftId = workHrsTxn.Shifts[index].ShiftId;
                            AddEmpShiftMap(schedulingDbContext, m);
                        }
                        index++;
                    }

                    dbContextTxn.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    dbContextTxn.Rollback();
                    throw ex;
                }
            }
        }
        public static void EnsureDbSeeded(this SchedulingDbContext context)
        {
            // ensure data is clean
            context.Routes.RemoveRange(context.Routes);
            context.Places.RemoveRange(context.Places);
            context.SaveChanges();

            var unionSt = new Place {
                Id = "Station0118", Name = "Union Street"
            };
            var winchester = new Place {
                Id = "Station0001", Name = "Winchester"
            };

            context.Places.Add(unionSt);
            context.Places.Add(winchester);
            context.SaveChanges();

            var routes = new List <Route>
            {
                new Route
                {
                    Id            = "trl-sthcrs",
                    OriginId      = unionSt.Id,
                    DestinationId = winchester.Id,
                    DepartUtc     = (new DateTime(2018, 09, 01))
                },
                new Route
                {
                    Id            = "sthcrs-trl",
                    OriginId      = winchester.Id,
                    DestinationId = unionSt.Id,
                    DepartUtc     = (new DateTime(2018, 10, 01))
                }
            };


            context.Routes.AddRange(routes);
            context.SaveChanges();
        }
示例#17
0
 public Handler(SchedulingDbContext db) : base(db)
 {
 }
示例#18
0
        public string Get(string reqType, string EmpIds, string dates)
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();
            SchedulingDbContext         schDbContext = new SchedulingDbContext(connString);
            MasterDbContext             masterDb     = new MasterDbContext(connString);

            try
            {
                List <DepartmentModel> allDeptsFromCache = (List <DepartmentModel>)DanpheCache.GetMasterData(MasterDataEnum.Department);
                List <EmployeeModel>   empListFromCache  = (List <EmployeeModel>)DanpheCache.GetMasterData(MasterDataEnum.Employee);

                #region GET: List of Employees
                if (reqType == "employeelist")
                {
                    var result = (from e in empListFromCache
                                  join d in allDeptsFromCache on e.DepartmentId equals d.DepartmentId
                                  select new
                    {
                        e.EmployeeId,
                        d.DepartmentId,
                        d.DepartmentName,
                        EmployeeName = e.Salutation + ". " + e.FirstName + " " + (string.IsNullOrEmpty(e.MiddleName) ? "" : e.MiddleName + " ") + e.LastName,
                    }).ToList();

                    responseData.Status  = "OK";
                    responseData.Results = result;
                }
                #endregion
                #region GET: Employee Schedules
                else if (reqType == "getEmpSchedule")
                {
                    string[]      employeeIDs = EmpIds.Split(',');
                    string[]      curDates    = dates.Split(',');
                    List <object> res         = new List <object>();

                    var abc = (from emp in empListFromCache
                               join dept in allDeptsFromCache on emp.DepartmentId equals dept.DepartmentId
                               join e in employeeIDs on emp.EmployeeId.ToString() equals e
                               select new
                    {
                        emp.EmployeeId,
                        EmployeeName = emp.Salutation + ". " + emp.FirstName + " " + (string.IsNullOrEmpty(emp.MiddleName) ? "" : emp.MiddleName + " ") + emp.LastName,
                        DepartmentName = dept.DepartmentName,
                        defSCH = (from daywise in schDbContext.DayWiseAvailability
                                  where daywise.EmployeeId == emp.EmployeeId
                                  select new
                        {
                            daywise.DayName,
                            IsWorkingDay = daywise.IsWorking
                        }).ToList(),
                        loadSCH = (from em in schDbContext.Employee
                                   join sch in schDbContext.EmpSchedules on em.EmployeeId equals sch.EmployeeId into schTemp
                                   from s in schTemp.DefaultIfEmpty()
                                   join date in curDates on s.Date.ToString() equals date
                                   where em.EmployeeId == emp.EmployeeId
                                   select new
                        {
                            Id = s.EmployeeSCHId,
                            TxnType = "Update",
                            Date = s.Date.Value,
                            s.DayName,
                            s.IsWorkingDay
                        }).ToList(),
                    }).ToList();

                    responseData.Status  = "OK";
                    responseData.Results = abc;
                }
                #endregion
                #region GET: list of shifts master
                else if (reqType == "getShiftList")
                {
                    var shiftList = schDbContext.ShiftsMaster.OrderByDescending(a => a.IsDefault).ToList();

                    responseData.Status  = "OK";
                    responseData.Results = shiftList;
                }
                #endregion
                #region GET: list of Employee working hours
                else if (reqType == "getEmpWHList")
                {
                    List <object> res = new List <object>();

                    var empDetails = (from emp in masterDb.Employees
                                      join dept in masterDb.Departments on emp.DepartmentId equals dept.DepartmentId
                                      join role in masterDb.EmployeeRole on emp.EmployeeRoleId equals role.EmployeeRoleId
                                      select new
                    {
                        emp.EmployeeId,
                        EmployeeName = emp.Salutation + ". " + emp.FirstName + " " + (string.IsNullOrEmpty(emp.MiddleName) ? "" : emp.MiddleName + " ") + emp.LastName,
                        emp.DepartmentId,
                        dept.DepartmentName,
                        emp.EmployeeRoleId,
                        role.EmployeeRoleName
                    }).ToList();

                    var empWorkingHours = (from emp in empDetails
                                           join m in schDbContext.EmpShiftMAP on emp.EmployeeId equals m.EmployeeId into mTemp
                                           from map in mTemp.DefaultIfEmpty()
                                           join shift in schDbContext.ShiftsMaster on(map != null ? map.ShiftId : 0) equals shift.ShiftId
                                           where (map != null ? map.IsActive : false) == true
                                           group new { emp, map, shift } by new
                    {
                        emp.EmployeeId,
                        emp.EmployeeName,
                        emp.EmployeeRoleName,
                        emp.DepartmentName
                    } into WH
                                           select new
                    {
                        WH.Key.EmployeeId,
                        WH.Key.EmployeeName,
                        WH.Key.DepartmentName,
                        WH.Key.EmployeeRoleName,
                        NoOfShifts = WH.Select(a => a.map.ShiftId).Count(),
                        Shifts = WH.Select(a => new
                        {
                            a.map.EmployeeShiftMapId,
                            a.map.ShiftId,
                            a.shift.ShiftName,
                            a.shift.StartTime,
                            a.shift.EndTime,
                            a.shift.TotalHrs,
                            a.map.IsActive,
                            a.shift.IsDefault
                            //,IsEditable = (from m in schDbContext.EmpShiftMAP
                            //              where m.ShiftId == a.map.ShiftId
                            //              select new { m.ShiftId }).Count().Equals(1)
                        }).OrderBy(z => z.StartTime).ToList(),
                        TotalWorkingHrs = WH.Sum(a => a.shift.TotalHrs)
                    }).ToList();

                    var empNOworkingHours = (from emp in empDetails
                                             where !schDbContext.EmpShiftMAP.Any(x => x.EmployeeId == emp.EmployeeId && x.IsActive == true)
                                             select new
                    {
                        emp.EmployeeId,
                        emp.EmployeeName,
                        emp.EmployeeRoleName,
                        emp.DepartmentName,
                        NoOfShifts = 0,
                        TotalWorkingHrs = 0
                    }).ToList();

                    foreach (var x in empWorkingHours)
                    {
                        res.Add(x);
                    }
                    foreach (var x in empNOworkingHours)
                    {
                        res.Add(x);
                    }

                    //var workingHours = (from map in schDbContext.EmpShiftMAP
                    //                    join e in schDbContext.Employee on map.EmployeeId equals e.EmployeeId
                    //                    join d in allDepts on e.DepartmentId equals d.DepartmentId
                    //                    join s in schDbContext.ShiftsMaster on map.ShiftId equals s.ShiftId
                    //                    join r in schDbContext.EmpRole on e.EmployeeRoleId equals r.EmployeeRoleId
                    //                    where map.IsActive == true
                    //                    group new { map, e, s } by new
                    //                    {
                    //                        e.EmployeeId,
                    //                        EmployeeName = e.Salutation + ". " + e.FirstName + " " + (string.IsNullOrEmpty(e.MiddleName) ? "" : e.MiddleName + " ") + e.LastName,
                    //                        d.DepartmentId,
                    //                        d.DepartmentName,
                    //                        r.EmployeeRoleName
                    //                    } into x
                    //                    select new
                    //                    {
                    //                        x.Key.EmployeeId,
                    //                        x.Key.EmployeeName,
                    //                        x.Key.DepartmentId,
                    //                        x.Key.DepartmentName,
                    //                        x.Key.EmployeeRoleName,
                    //                        NoOfShifts = x.Select(a => a.map.ShiftId).Count(),
                    //                        Shifts = x.Select(a => new
                    //                        {
                    //                            a.map.EmployeeShiftMapId,
                    //                            a.map.ShiftId,
                    //                            a.s.ShiftName,
                    //                            a.s.StartTime,
                    //                            a.s.EndTime,
                    //                            a.s.TotalHrs,
                    //                            a.map.IsActive,
                    //                            a.s.IsDefault
                    //                            //,IsEditable = (from m in schDbContext.EmpShiftMAP
                    //                            //              where m.ShiftId == a.map.ShiftId
                    //                            //              select new { m.ShiftId }).Count().Equals(1)
                    //                        }).OrderBy(z => z.StartTime).ToList(),
                    //                        TotalWorkingHrs = x.Sum(a => a.s.TotalHrs)
                    //                    }).ToList();

                    responseData.Status  = "OK";
                    responseData.Results = res;
                }
                #endregion
                #region GET: list of default shifts master
                else if (reqType == "getDefaultShifts")
                {
                    var defShifts = (from s in schDbContext.ShiftsMaster
                                     where s.IsDefault == true
                                     select s).OrderBy(x => x.StartTime).ToList();

                    responseData.Status  = "OK";
                    responseData.Results = defShifts;
                }
                #endregion
                #region
                else if (reqType == "getEmployeeNoShift")
                {
                    //getting employee that doesnt have any active shift assigned to him/her (from EmployeeShiftMAP table)
                    var empList = (from e in empListFromCache
                                   where !schDbContext.EmpShiftMAP.Any(x => x.EmployeeId == e.EmployeeId && x.IsActive == true)
                                   select e).ToList();

                    responseData.Status  = "OK";
                    responseData.Results = empList;
                }
                #endregion
            }

            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }

            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
示例#19
0
        public string Post()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();
            SchedulingDbContext         schDbContext = new SchedulingDbContext(connString);
            string reqType = this.ReadQueryStringData("reqType");
            string str     = this.ReadPostData();

            try
            {
                #region Employee Schedule manage : Insert/Update schedules
                if (reqType == "manageEmpSchedules")
                {
                    List <EmpSchedules> schedulesData = DanpheJSONConvert.DeserializeObject <List <EmpSchedules> >(str);

                    Boolean Flag = false;
                    Flag = SchedulingBL.ManageEmpSchedules(schedulesData, schDbContext);
                    if (Flag)
                    {
                        responseData.Status  = "OK";
                        responseData.Results = 1;
                    }
                    else
                    {
                        responseData.ErrorMessage = "check console for error details.";
                        responseData.Status       = "Failed";
                    }
                }
                #endregion
                #region Add Shift (Manage Shifts)
                else if (reqType == "AddShift")
                {
                    ShiftsMasterModel shiftMaster = DanpheJSONConvert.DeserializeObject <ShiftsMasterModel>(str);
                    shiftMaster.CreatedOn = System.DateTime.Now;
                    schDbContext.ShiftsMaster.Add(shiftMaster);
                    schDbContext.SaveChanges();
                    responseData.Status  = "OK";
                    responseData.Results = shiftMaster;
                }
                #endregion
                #region Employee Working Hours manage Transaction
                else if (reqType == "EmpWokringHours")
                {
                    WorkingHoursTxnVM workHrsTxnData = DanpheJSONConvert.DeserializeObject <WorkingHoursTxnVM>(str);

                    Boolean Flag = false;
                    Flag = SchedulingBL.WorkingHrsTxn(workHrsTxnData, schDbContext);
                    if (Flag)
                    {
                        responseData.Status  = "OK";
                        responseData.Results = 1;
                    }
                    else
                    {
                        responseData.ErrorMessage = "check console for error details.";
                        responseData.Status       = "Failed";
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }

            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
 public WeekDayRepository(SchedulingDbContext context) : base(context)
 {
 }
示例#21
0
 public CurriculumRepository(SchedulingDbContext context) : base(context)
 {
 }
 public InstructorRepository(SchedulingDbContext context) : base(context)
 {
 }
示例#23
0
 public Validator(SchedulingDbContext db)
 {
     RuleFor(x => x.StationId)
     .EntityMustExist <Command, Guid, Station>(db);
 }
示例#24
0
 public TypeRepository(SchedulingDbContext context) : base(context)
 {
 }
示例#25
0
 public RoomRepository(SchedulingDbContext context) : base(context)
 {
 }
示例#26
0
 public TypesController(SchedulingDbContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
示例#27
0
 public PlaceRepository(SchedulingDbContext schedulingDbContext)
 {
     _schedulingDbContext = schedulingDbContext;
 }
示例#28
0
 public DepartmentRepository(SchedulingDbContext context) : base(context)
 {
 }
示例#29
0
 public RouteRepository(SchedulingDbContext schedulingDbContext)
 {
     _schedulingDbContext = schedulingDbContext;
 }
示例#30
0
 public Scheduler(SchedulingDbContext db)
 {
     this.db = db;
 }