コード例 #1
0
        public void SaveItem(TimeSheetItem timeSheetItem, string changedPropertyName)
        {
            if (timeSheetItem == null)
            {
                throw new ArgumentNullException("timeSheetItem");
            }
            if (string.IsNullOrWhiteSpace(changedPropertyName))
            {
                throw new ArgumentNullException("changedPropertyName");
            }

            using (var transactionScope = new TransactionScope())
            {
                using (var appDbContext = new AppDbContext())
                {
                    var original =
                        appDbContext.TimeSheetItems
                        .SingleOrDefault(t => t.WorkItemId.Equals(timeSheetItem.WorkItemId) &&
                                         t.UserName.Equals(_tfsDataService.UserUniqueName));

                    // Create a new item when it doesn't exist in the Db
                    if (original == null)
                    {
                        original = new TimeSheetItem
                        {
                            WorkItemId     = timeSheetItem.WorkItemId,
                            Project        = _project,
                            ServerUrl      = _url,
                            Name           = timeSheetItem.Name,
                            FirstDayOfWeek = timeSheetItem.FirstDayOfWeek,
                            UserName       = _tfsDataService.UserUniqueName
                        };
                        appDbContext.TimeSheetItems.Add(original);
                    }

                    var property = typeof(TimeSheetItem).GetProperty(changedPropertyName);
                    // Check if we're updating the effort
                    if (property.PropertyType == typeof(DateTime))
                    {
                        var delta = GetDateTimeDelta(timeSheetItem, original, property);

                        _tfsDataService.UpdateWorkItemEffort(original.WorkItemId, delta);

                        // Update the object with the delta and save it into the Db
                        property.SetValue(original, Convert.ToDateTime(property.GetValue(original)).Add(delta));
                        appDbContext.SaveChanges();
                    }
                    // Or if we're updating the state
                    else if (property.Name.Equals("IsClosed"))
                    {
                        _tfsDataService.UpdateWorkItemClosedState(original.WorkItemId);

                        appDbContext.SaveChanges();
                    }

                    // Commit the entire transaction
                    transactionScope.Complete();
                }
            }
        }
コード例 #2
0
        //[Authorize]
        public IActionResult Post([FromForm] addvalue value)
        {
            TimeSheet      timeSheet      = new TimeSheet();
            TimeSheetItem  timeSheetItem  = new TimeSheetItem();
            TimeSheetEntry timeSheetEntry = new TimeSheetEntry();

            try
            {
                //TimeSheet obj = JsonConvert.DeserializeObject<TimeSheet>(value);

                timeSheet.EmpId         = value.EmpId;
                timeSheetItem.Hours     = value.Hours;
                timeSheetItem.EmpId     = value.EmpId;
                timeSheetEntry.Customer = value.Customer;
                timeSheetEntry.Company  = value.Company;
                timeSheetEntry.Task     = value.Task;
                timeSheetEntry.Project  = value.Project;
                timeSheetEntry.EmpId    = value.EmpId;
                timeSheetEntry.Status   = "pending";

                timeSheetItem.Date          = "null";
                timeSheetItem.From          = "null";
                timeSheetItem.To            = "null";
                timeSheet.EmployeeName      = "null";
                timeSheetEntry.EmployeeName = timeSheet.EmployeeName;
                timeSheet.Id      = 1;
                timeSheetEntry.Id = timeSheet.Id;
                timeSheetItem.Id  = 1;



                db.TimeSheet.Add(timeSheet);
                db.TimeSheetItem.Add(timeSheetItem);
                db.TimeSheetEntry.Add(timeSheetEntry);
                db.SaveChanges();
                return(Ok(new
                {
                    StatusCode = 200,
                    Message = "done",
                    //  data = q
                }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Ok(new
                {
                    StatusCode = 500,
                    Message = "unauthorized"
                }));
            }
        }
コード例 #3
0
        public IActionResult save([FromBody] AddTimeSheet items)
        {
            try
            {
                TimeSheet timeSheet = new TimeSheet();


                var existingEmployeee = db.TimeSheet.FirstOrDefault(item => items.Empid == item.Empid);
                if (existingEmployeee == null)
                {
                    timeSheet.Empid   = items.Empid;
                    timeSheet.Empname = items.Empname;
                    db.Add(timeSheet);
                    db.SaveChanges();
                }
                foreach (TimeSheetData value in items.data)
                {
                    TimeSheetItem  timeSheetItem  = new TimeSheetItem();
                    TimeSheetEntry timeSheetEntry = new TimeSheetEntry();
                    timeSheetItem.Hours       = value.Hours;
                    timeSheetItem.Empid       = items.Empid;
                    timeSheetItem.Status      = "Drafted";
                    timeSheetItem.Submittedto = value.Submittedto;
                    timeSheetItem.To          = items.To;
                    timeSheetItem.From        = items.From;
                    timeSheetItem.Date        = value.Date;
                    db.Add(timeSheetItem);
                    db.SaveChanges();
                    int index = timeSheetItem.Timestampid;

                    timeSheetEntry.Customer    = value.Customer;
                    timeSheetEntry.Company     = value.Company;
                    timeSheetEntry.Task        = value.Task;
                    timeSheetEntry.Project     = value.Project;
                    timeSheetEntry.Timestampid = index;

                    db.Add(timeSheetEntry);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            return(Ok());
        }
コード例 #4
0
        private static TimeSpan GetDateTimeDelta(TimeSheetItem timeSheetItem, TimeSheetItem original, PropertyInfo property)
        {
            // Get the original value or get the default value
            var defaultDateTime = new TimeSheetItem().Monday;

            var originalValue = original == null
                                                                        ? defaultDateTime
                                                                        : Convert.ToDateTime(property.GetValue(original));

            var changedValue = Convert.ToDateTime(property.GetValue(timeSheetItem));

            // Sanity check to make sure we're not adding a massive amount of time
            // And to make sure we can save the datetime into sql Db
            changedValue = new DateTime(defaultDateTime.Year, defaultDateTime.Month, defaultDateTime.Day,
                                        changedValue.Hour, changedValue.Minute, changedValue.Second);

            // Determine the delta between the to datetimes
            return(changedValue.Subtract(originalValue));
        }
コード例 #5
0
        private void UpdateTotalRecord()
        {
            _week.Remove(_week.SingleOrDefault(t => t.IsTotal));
            var total = new TimeSheetItem {
                IsTotal = true, Name = "TOTAL"
            };

            foreach (var item in _week)
            {
                total.WorkRemaining = total.WorkRemaining
                                      .AddHours(item.WorkRemaining.Hour)
                                      .AddMinutes(item.WorkRemaining.Minute)
                                      .AddSeconds(item.WorkRemaining.Second);
                total.Monday = total.Monday
                               .AddHours(item.Monday.Hour)
                               .AddMinutes(item.Monday.Minute)
                               .AddSeconds(item.Monday.Second);
                total.Tuesday = total.Tuesday
                                .AddHours(item.Tuesday.Hour)
                                .AddMinutes(item.Tuesday.Minute)
                                .AddSeconds(item.Tuesday.Second);
                total.Wednesday = total.Wednesday
                                  .AddHours(item.Wednesday.Hour)
                                  .AddMinutes(item.Wednesday.Minute)
                                  .AddSeconds(item.Wednesday.Second);
                total.Thursday = total.Thursday
                                 .AddHours(item.Thursday.Hour)
                                 .AddMinutes(item.Thursday.Minute)
                                 .AddSeconds(item.Thursday.Second);
                total.Friday = total.Friday
                               .AddHours(item.Friday.Hour)
                               .AddMinutes(item.Friday.Minute)
                               .AddSeconds(item.Friday.Second);
            }
            _week.Add(total);
        }
コード例 #6
0
        public JsonResult getTimeSheet(string dateSelected)
        {
            string str = " to ";

            string[]         dates      = dateSelected.Split(str.ToCharArray());
            var              day1       = DateTime.Parse(dates[0]);
            var              timesheets = es.getTimeSheet(DateTime.Parse(dates[0]), User.Identity.Name);
            List <TimeInOut> timeinouts = new List <TimeInOut>();

            if (timesheets != null && timesheets.TimeInOuts != null)
            {
                timeinouts = timesheets.TimeInOuts.ToList();
            }
            ModelStack           mdl       = new ModelStack();
            TimeSheetModel       tsm       = new TimeSheetModel();
            TimeSheetItem        tItem     = new TimeSheetItem();
            List <TimeSheetItem> timeItems = new List <TimeSheetItem>();

            var svc = Session["svc"] == null?es.getServiceCodes() : (List <serviceCode>)Session["svc"];

            var plans = Session["plans"] == null?es.getPlans() : (List <planSection>)Session["plans"];

            Session["svc"]   = svc;
            Session["plans"] = plans;
            tsm.empName      = Session["username"] == null?es.getUsername(User.Identity.Name) : Session["username"].ToString();

            Session["username"] = tsm.empName;

            svc srv = new Models.svc();

            tsm.serviceCodes = new List <Models.svc>();
            tsm.PlanSections = new List <plan>();
            foreach (var item in svc)
            {
                srv.Id   = item.Id;
                srv.Name = item.Name;
                tsm.serviceCodes.Add(srv);
                srv = new Models.svc();
            }
            plan pln = new Models.plan();

            foreach (var item in plans)
            {
                pln.Id   = item.Id;
                pln.Name = item.Name;
                tsm.PlanSections.Add(pln);
                pln = new Models.plan();
            }
            if (timesheets == null)
            {
                tsm.Id         = 0;
                tsm.isViewOnly = false;
                tsm.isBackup   = null;
                tsm.isLiveIn   = null;
                tsm.startDate  = day1;
                tsm.items      = new List <TimeSheetItem>();
                for (int i = 0; i < 7; i++)
                {
                    tItem.Id      = 0;
                    tItem.dayDate = day1.ToShortDateString();
                    tItem.dayName = day1.ToString("dddd");
                    day1          = day1.AddDays(1);
                    tItem.dates   = dates;
                    tItem.times   = new List <times>();
                    tItem.times.Add(new times());
                    tsm.items.Add(tItem);
                    tItem = new TimeSheetItem();
                }
            }
            else
            {
                tsm.Id = timesheets.Id;

                if (timesheets.isDraft != null && timesheets.isDraft.Value == true)
                {
                    tsm.isViewOnly = false;
                    tsm.isDraft    = true;
                }
                else
                {
                    tsm.isViewOnly = true;
                    tsm.isDraft    = false;
                }
                if (timesheets.isBackup != null)
                {
                    tsm.isBackup = timesheets.isBackup.Value;
                }
                if (timesheets.isLiveIn != null)
                {
                    tsm.isLiveIn = timesheets.isLiveIn.Value;
                }
                if (timesheets.DayDate != null)
                {
                    tsm.startDate = timesheets.DayDate.Value;
                }
                tsm.items = new List <TimeSheetItem>();


                if (timesheets.fk_statusid == 3)
                {
                    tsm.isViewOnly = false;
                    for (int i = 0; i < 7; i++)
                    {
                        var items      = timeinouts.Where(x => x.dayDate.Value.Date.ToShortDateString() == day1.ToShortDateString()).ToList();
                        var dateditems = items.GroupBy(x => x.dayDate);
                        if (items.Count > 0)
                        {
                            foreach (var itemsvals in dateditems)
                            {
                                var itemvals = itemsvals.ToList();
                                var time2    = false;
                                foreach (var item in itemvals)
                                {
                                    if (time2 == false)
                                    {
                                        time2 = item.TimeIn2H1 != null;
                                    }
                                    tItem.Id      = item.Id;
                                    tItem.dayDate = item.dayDate.Value.Date.ToShortDateString();;
                                    tItem.dayName = item.dayDate.Value.ToString("dddd"); //config
                                    if (tsm.HasTime2 != true)
                                    {
                                        tsm.HasTime2 = item.TimeIn2H1 != null;
                                    }
                                    times timesitem = new times();
                                    if (item.fk_plansection != null)
                                    {
                                        timesitem.plansectionId = item.fk_plansection.Value;
                                    }
                                    if (item.isInAM != null)
                                    {
                                        timesitem.isAmIn = item.isInAM.Value.ToString().ToLower();
                                    }
                                    if (item.isOutAM != null)
                                    {
                                        timesitem.isAmOut = item.isOutAM.Value.ToString().ToLower();
                                    }
                                    if (item.fk_serviceCode != null)
                                    {
                                        timesitem.serviceCodeId = item.fk_serviceCode.Value;
                                    }
                                    //time.serviceCodes = svc;
                                    if (item.TimeInH1 != null)
                                    {
                                        timesitem.TimeInH1 = item.TimeInH1.ToString();
                                    }
                                    if (item.TimeInM1 != null)
                                    {
                                        timesitem.TimeInM1 = item.TimeInM1.ToString();
                                    }
                                    if (item.TimeOutH1 != null)
                                    {
                                        timesitem.TimeOutH1 = item.TimeOutH1.ToString();
                                    }
                                    if (item.TimeOutM1 != null)
                                    {
                                        timesitem.TimeOutM1 = item.TimeOutM1.ToString();
                                    }

                                    if (item.TimeIn2H1 != null)
                                    {
                                        if (item.TimeIn2H1 != null)
                                        {
                                            timesitem.TimeIn2H1 = item.TimeIn2H1.ToString();
                                        }
                                        if (item.TimeIn2M1 != null)
                                        {
                                            timesitem.TimeIn2M1 = item.TimeIn2M1.ToString();
                                        }
                                        if (item.TimeOut2H1 != null)
                                        {
                                            timesitem.TimeOut2H1 = item.TimeOut2H1.ToString();
                                        }
                                        if (item.TimeOut2M1 != null)
                                        {
                                            timesitem.TimeOut2M1 = item.TimeOut2M1.ToString();
                                        }
                                        if (item.isInAM2 != null)
                                        {
                                            timesitem.isAmIn2 = item.isInAM2.Value.ToString().ToLower();
                                        }
                                        if (item.isOutAM2 != null)
                                        {
                                            timesitem.isAmOut2 = item.isOutAM2.Value.ToString().ToLower();
                                        }
                                        timesitem.Time2 = true;
                                        tsm.HasTime2    = true;
                                    }
                                    else
                                    {
                                        timesitem.Time2 = time2;
                                    }
                                    tItem.dates = dates;
                                    if (tItem.times == null)
                                    {
                                        tItem.times = new List <times>();
                                    }
                                    tItem.times.Add(timesitem);
                                    // tItem.serviceCodeId = item.serviceCode.Id;
                                }
                                tsm.items.Add(tItem);

                                tItem = new TimeSheetItem();
                            }
                        }
                        else
                        {
                            tItem.Id      = 0;
                            tItem.dayDate = day1.ToShortDateString();

                            tItem.dayName = day1.ToString("dddd");
                            tItem.dates   = dates;
                            tItem.times   = new List <times>();
                            tItem.times.Add(new times());

                            tsm.items.Add(tItem);
                        }
                        day1  = day1.AddDays(1);
                        tItem = new TimeSheetItem();
                    }
                }

                else
                {
                    var items      = timeinouts;
                    var dateditems = items.GroupBy(x => x.dayDate);
                    foreach (var itemsvals in dateditems)
                    {
                        var itemvals = itemsvals.ToList();
                        var time2    = false;
                        foreach (var item in itemvals)
                        {
                            if (time2 == false)
                            {
                                time2 = item.TimeIn2H1 != null;
                            }
                            tItem.Id      = item.Id;
                            tItem.dayDate = item.dayDate.Value.Date.ToShortDateString();;
                            tItem.dayName = item.dayDate.Value.ToString("dddd"); //config
                            if (tsm.HasTime2 != true)
                            {
                                tsm.HasTime2 = item.TimeIn2H1 != null;
                            }
                            times timesitem = new times();
                            if (item.fk_plansection != null)
                            {
                                timesitem.plansectionId = item.fk_plansection.Value;
                            }
                            if (item.isInAM != null)
                            {
                                timesitem.isAmIn = item.isInAM.Value.ToString().ToLower();
                            }
                            if (item.isOutAM != null)
                            {
                                timesitem.isAmOut = item.isOutAM.Value.ToString().ToLower();
                            }
                            if (item.fk_serviceCode != null)
                            {
                                timesitem.serviceCodeId = item.fk_serviceCode.Value;
                            }
                            //time.serviceCodes = svc;
                            if (item.TimeInH1 != null)
                            {
                                timesitem.TimeInH1 = item.TimeInH1.ToString();
                            }
                            if (item.TimeInM1 != null)
                            {
                                timesitem.TimeInM1 = item.TimeInM1.ToString();
                            }
                            if (item.TimeOutH1 != null)
                            {
                                timesitem.TimeOutH1 = item.TimeOutH1.ToString();
                            }
                            if (item.TimeOutM1 != null)
                            {
                                timesitem.TimeOutM1 = item.TimeOutM1.ToString();
                            }

                            if (item.TimeIn2H1 != null)
                            {
                                if (item.TimeIn2H1 != null)
                                {
                                    timesitem.TimeIn2H1 = item.TimeIn2H1.ToString();
                                }
                                if (item.TimeIn2M1 != null)
                                {
                                    timesitem.TimeIn2M1 = item.TimeIn2M1.ToString();
                                }
                                if (item.TimeOut2H1 != null)
                                {
                                    timesitem.TimeOut2H1 = item.TimeOut2H1.ToString();
                                }
                                if (item.TimeOut2M1 != null)
                                {
                                    timesitem.TimeOut2M1 = item.TimeOut2M1.ToString();
                                }
                                if (item.isInAM2 != null)
                                {
                                    timesitem.isAmIn2 = item.isInAM2.Value.ToString().ToLower();
                                }
                                if (item.isOutAM2 != null)
                                {
                                    timesitem.isAmOut2 = item.isOutAM2.Value.ToString().ToLower();
                                }
                                timesitem.Time2 = true;
                                tsm.HasTime2    = true;
                            }
                            else
                            {
                                timesitem.Time2 = time2;
                            }

                            tItem.dates = dates;


                            if (tItem.times == null)
                            {
                                tItem.times = new List <times>();
                            }
                            tItem.times.Add(timesitem);
                            // tItem.serviceCodeId = item.serviceCode.Id;
                        }

                        if (time2 == true)
                        {
                            foreach (var item in tItem.times)
                            {
                                item.Time2 = true;
                            }
                        }

                        timeItems.Add(tItem);

                        tItem = new TimeSheetItem();
                    }
                    tsm.items = timeItems;
                }
            }
            mdl.model      = tsm;
            mdl.modelstack = new List <TimeSheetModel>();
            // mdl.modelstack.Add(tsm);
            return(Json(mdl));
        }