예제 #1
0
        // GET: /Timesheet/Edit/<id>
        public ActionResult Edit(
            Int32?TimesheetID
            )
        {
            if (
                TimesheetID == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Timesheet Timesheet = new Timesheet();

            Timesheet.TimesheetID = System.Convert.ToInt32(TimesheetID);
            Timesheet             = TimesheetData.Select_Record(Timesheet);

            if (Timesheet == null)
            {
                return(HttpNotFound());
            }
            // ComboBox
            ViewData["EmployeeID"] = new SelectList(Timesheet_EmployeeData.List(), "EmployeeID", "FirstName", Timesheet.EmployeeID);
            ViewData["ProjectID"]  = new SelectList(Timesheet_ProjectData.List(), "ProjectID", "ProjectName", Timesheet.ProjectID);

            return(View(Timesheet));
        }
        public async Task <ActionResult> CreateTimesheetEntry(List <TimesheetViewModel> models = null)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.Name;//.GetUserId();
                //ApplicationUser user = null;

                foreach (var model in models)
                {
                    var timesheetData = new TimesheetData
                    {
                        ActivityId    = model.ActivityId,
                        TimeSheetDate = model.TimeSheetDate,
                        NoOfHours     = model.NoOfHours,
                        ProjectId     = model.ProjectId
                    };
                    db.Timedata.Add(timesheetData);
                }
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Projects", new { id = models[0].ProjectId }));
            }

            ViewBag.ActivityTypes = db.ActivityTypes.ToList();
            // ViewBag.MemberList = db.Projects.Where(p => p.ProjectID == models[0].ProjectId).SelectMany(p => p.ApplicationUsers).ToList();
            return(View(models));
        }
예제 #3
0
        public ActionResult Edit(Timesheet Timesheet)
        {
            Timesheet oTimesheet = new Timesheet();

            oTimesheet.TimesheetID = System.Convert.ToInt32(Timesheet.TimesheetID);
            oTimesheet             = TimesheetData.Select_Record(Timesheet);

            if (ModelState.IsValid)
            {
                bool bSucess = false;
                bSucess = TimesheetData.Update(oTimesheet, Timesheet);
                if (bSucess == true)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Can Not Update");
                }
            }
            // ComboBox
            ViewData["EmployeeID"] = new SelectList(Timesheet_EmployeeData.List(), "EmployeeID", "FirstName", Timesheet.EmployeeID);
            ViewData["ProjectID"]  = new SelectList(Timesheet_ProjectData.List(), "ProjectID", "ProjectName", Timesheet.ProjectID);

            return(View(Timesheet));
        }
예제 #4
0
        public ActionResult Create([Bind(Include =
                                             "EmployeeID"
                                             + "," + "ProjectID"
                                             + "," + "EntryDate"
                                             + "," + "StartTime"
                                             + "," + "EndTime"
                                             + "," + "TotTime"
                                             + "," + "Remarks"
                                         )] Timesheet Timesheet)
        {
            if (ModelState.IsValid)
            {
                bool bSucess = false;
                bSucess = TimesheetData.Add(Timesheet);
                if (bSucess == true)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Can Not Insert");
                }
            }
            // ComboBox
            ViewData["EmployeeID"] = new SelectList(Timesheet_EmployeeData.List(), "EmployeeID", "FirstName", Timesheet.EmployeeID);
            ViewData["ProjectID"]  = new SelectList(Timesheet_ProjectData.List(), "ProjectID", "ProjectName", Timesheet.ProjectID);

            return(View(Timesheet));
        }
        /// <summary>
        /// Inserting or updating timesheet data
        /// </summary>
        /// <param name="timesheetData"></param>
        /// <returns></returns>
        public async Task <bool> InsertUpdate(TimesheetData timesheetData)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(timesheetData), UnicodeEncoding.UTF8, "application/json");

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = await client.PostAsync(_baseurl + "/timesheetData/insertUpdate", stringContent);

                if (response.IsSuccessStatusCode)
                {
                    await response.Content.ReadAsStringAsync();
                }
            }
            return(true);
        }
예제 #6
0
        /// <summary>
        /// InsertUpdate
        /// </summary>
        /// <param name="timesheetData"></param>
        public void InsertUpdate(TimesheetData timesheetData)
        {
            TimesheetData existingObj = this.db.TimesheetData
                                        .Where(x => x.WorkingDay == timesheetData.WorkingDay && x.EmployeeId == timesheetData.EmployeeId && x.TaskId == timesheetData.TaskId).SingleOrDefault();

            using (var context = db)
            {
                if (existingObj != null)
                {
                    existingObj.NoofHrs = timesheetData.NoofHrs;
                    context.TimesheetData.Update(existingObj);
                    context.SaveChanges();
                }
                else
                {
                    context.TimesheetData.Add(timesheetData);
                    context.SaveChanges();
                }
            }
        }
예제 #7
0
        public ActionResult DeleteConfirmed(
            Int32?TimesheetID
            )
        {
            Timesheet Timesheet = new Timesheet();

            Timesheet.TimesheetID = System.Convert.ToInt32(TimesheetID);
            Timesheet             = TimesheetData.Select_Record(Timesheet);

            bool bSucess = false;

            bSucess = TimesheetData.Delete(Timesheet);
            if (bSucess == true)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Can Not Delete");
            }
            return(null);
        }
예제 #8
0
        // GET: /Timesheet/Delete/<id>
        public ActionResult Delete(
            Int32?TimesheetID
            )
        {
            if (
                TimesheetID == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            dtEmployee = Timesheet_EmployeeData.SelectAll();
            dtProject  = Timesheet_ProjectData.SelectAll();

            Timesheet Timesheet = new Timesheet();

            Timesheet.TimesheetID = System.Convert.ToInt32(TimesheetID);
            Timesheet             = TimesheetData.Select_Record(Timesheet);
            Timesheet.Employee    = new Employee()
            {
                EmployeeID  = (Int32)Timesheet.EmployeeID
                , FirstName = (from DataRow rowEmployee in dtEmployee.Rows
                               where Timesheet.EmployeeID == (int)rowEmployee["EmployeeID"]
                               select(String) rowEmployee["FirstName"]).FirstOrDefault()
            };
            Timesheet.Project = new Project()
            {
                ProjectID     = (Int32)Timesheet.ProjectID
                , ProjectName = (from DataRow rowProject in dtProject.Rows
                                 where Timesheet.ProjectID == (int)rowProject["ProjectID"]
                                 select(String) rowProject["ProjectName"]).FirstOrDefault()
            };

            if (Timesheet == null)
            {
                return(HttpNotFound());
            }
            return(View(Timesheet));
        }
예제 #9
0
        /// <summary>
        /// Button event for saving details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void saveClick(object sender, RoutedEventArgs e)
        {
            int userVal;

            lblerr.Content = string.Empty;
            if (txtHrs.Text != string.Empty && int.TryParse(txtHrs.Text, out userVal))
            {
                TimesheetData objTimesheetData = new TimesheetData();
                objTimesheetData.EmployeeId = Convert.ToInt16(ddlEmployee.SelectedValue);
                objTimesheetData.TaskId     = Convert.ToInt16(ddlTask.SelectedValue);
                objTimesheetData.NoofHrs    = Convert.ToInt16(userVal);
                objTimesheetData.workingDay = Convert.ToDateTime(txtSelected.Text);
                EmployeeViewModel objEmployeeService = new EmployeeViewModel();
                Task.Run(() => objEmployeeService.LoadInsert(objTimesheetData));
                Thread.Sleep(1000);
                popupAdd.IsOpen = false;
                populateTimesheetDetails(DateTime.Now.Subtract(new TimeSpan((int)DateTime.Now.DayOfWeek, 0, 0, 0)), DateTime.Now.AddDays(7), ddlEmployee.SelectedValue.ToString());
            }
            else
            {
                lblerr.Content = "Input is not correct (Hrs)";
            }
        }
 public void InsertUpdate(TimesheetData timesheetData)
 {
     this.timesheetService.InsertUpdate(timesheetData);
 }
예제 #11
0
 /// <summary>
 /// LoadInsert
 /// </summary>
 /// <param name="timesheetData"></param>
 /// <returns></returns>
 public async Task LoadInsert(TimesheetData timesheetData)
 {
     await this._employeeService.InsertUpdate(timesheetData);
 }
예제 #12
0
        // GET: /Timesheet/
        public ActionResult Index(string sortOrder,
                                  String SearchField,
                                  String SearchCondition,
                                  String SearchText,
                                  String Export,
                                  int?PageSize,
                                  int?page,
                                  string command)
        {
            if (command == "Show All")
            {
                SearchField                = null;
                SearchCondition            = null;
                SearchText                 = null;
                Session["SearchField"]     = null;
                Session["SearchCondition"] = null;
                Session["SearchText"]      = null;
            }
            else if (command == "Add New Record")
            {
                return(RedirectToAction("Create"));
            }
            else if (command == "Export")
            {
                Session["Export"] = Export;
            }
            else if (command == "Search" | command == "Page Size")
            {
                if (!string.IsNullOrEmpty(SearchText))
                {
                    Session["SearchField"]     = SearchField;
                    Session["SearchCondition"] = SearchCondition;
                    Session["SearchText"]      = SearchText;
                }
            }
            if (command == "Page Size")
            {
                Session["PageSize"] = PageSize;
            }

            ViewData["SearchFields"]     = GetFields((Session["SearchField"] == null ? "Timesheet I D" : Convert.ToString(Session["SearchField"])));
            ViewData["SearchConditions"] = Library.GetConditions((Session["SearchCondition"] == null ? "Contains" : Convert.ToString(Session["SearchCondition"])));
            ViewData["SearchText"]       = Session["SearchText"];
            ViewData["Exports"]          = Library.GetExports((Session["Export"] == null ? "Pdf" : Convert.ToString(Session["Export"])));
            ViewData["PageSizes"]        = Library.GetPageSizes();

            ViewData["CurrentSort"]         = sortOrder;
            ViewData["TimesheetIDSortParm"] = sortOrder == "TimesheetID_asc" ? "TimesheetID_desc" : "TimesheetID_asc";
            ViewData["EmployeeIDSortParm"]  = sortOrder == "EmployeeID_asc" ? "EmployeeID_desc" : "EmployeeID_asc";
            ViewData["ProjectIDSortParm"]   = sortOrder == "ProjectID_asc" ? "ProjectID_desc" : "ProjectID_asc";
            ViewData["EntryDateSortParm"]   = sortOrder == "EntryDate_asc" ? "EntryDate_desc" : "EntryDate_asc";
            ViewData["StartTimeSortParm"]   = sortOrder == "StartTime_asc" ? "StartTime_desc" : "StartTime_asc";
            ViewData["EndTimeSortParm"]     = sortOrder == "EndTime_asc" ? "EndTime_desc" : "EndTime_asc";
            ViewData["TotTimeSortParm"]     = sortOrder == "TotTime_asc" ? "TotTime_desc" : "TotTime_asc";
            ViewData["RemarksSortParm"]     = sortOrder == "Remarks_asc" ? "Remarks_desc" : "Remarks_asc";

            dtTimesheet = TimesheetData.SelectAll();
            dtEmployee  = Timesheet_EmployeeData.SelectAll();
            dtProject   = Timesheet_ProjectData.SelectAll();

            try
            {
                if (!string.IsNullOrEmpty(Convert.ToString(Session["SearchField"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchCondition"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchText"])))
                {
                    dtTimesheet = TimesheetData.Search(Convert.ToString(Session["SearchField"]), Convert.ToString(Session["SearchCondition"]), Convert.ToString(Session["SearchText"]));
                }
            }
            catch { }

            var Query = from rowTimesheet in dtTimesheet.AsEnumerable()
                        join rowEmployee in dtEmployee.AsEnumerable() on rowTimesheet.Field <Int32>("EmployeeID") equals rowEmployee.Field <Int32>("EmployeeID")
                        join rowProject in dtProject.AsEnumerable() on rowTimesheet.Field <Int32>("ProjectID") equals rowProject.Field <Int32>("ProjectID")
                        select new Timesheet()
            {
                TimesheetID = rowTimesheet.Field <Int32>("TimesheetID")
                ,
                Employee = new Employee()
                {
                    EmployeeID  = rowEmployee.Field <Int32>("EmployeeID")
                    , FirstName = rowEmployee.Field <String>("FirstName")
                }
                ,
                Project = new Project()
                {
                    ProjectID     = rowProject.Field <Int32>("ProjectID")
                    , ProjectName = rowProject.Field <String>("ProjectName")
                }
                , EntryDate = rowTimesheet.Field <DateTime>("EntryDate")
                , StartTime = rowTimesheet.Field <DateTime>("StartTime")
                , EndTime   = rowTimesheet.Field <DateTime>("EndTime")
                , TotTime   = rowTimesheet.Field <String>("TotTime")
                , Remarks   = rowTimesheet.Field <String>("Remarks")
            };

            switch (sortOrder)
            {
            case "TimesheetID_desc":
                Query = Query.OrderByDescending(s => s.TimesheetID);
                break;

            case "TimesheetID_asc":
                Query = Query.OrderBy(s => s.TimesheetID);
                break;

            case "EmployeeID_desc":
                Query = Query.OrderByDescending(s => s.Employee.FirstName);
                break;

            case "EmployeeID_asc":
                Query = Query.OrderBy(s => s.Employee.FirstName);
                break;

            case "ProjectID_desc":
                Query = Query.OrderByDescending(s => s.Project.ProjectName);
                break;

            case "ProjectID_asc":
                Query = Query.OrderBy(s => s.Project.ProjectName);
                break;

            case "EntryDate_desc":
                Query = Query.OrderByDescending(s => s.EntryDate);
                break;

            case "EntryDate_asc":
                Query = Query.OrderBy(s => s.EntryDate);
                break;

            case "StartTime_desc":
                Query = Query.OrderByDescending(s => s.StartTime);
                break;

            case "StartTime_asc":
                Query = Query.OrderBy(s => s.StartTime);
                break;

            case "EndTime_desc":
                Query = Query.OrderByDescending(s => s.EndTime);
                break;

            case "EndTime_asc":
                Query = Query.OrderBy(s => s.EndTime);
                break;

            case "TotTime_desc":
                Query = Query.OrderByDescending(s => s.TotTime);
                break;

            case "TotTime_asc":
                Query = Query.OrderBy(s => s.TotTime);
                break;

            case "Remarks_desc":
                Query = Query.OrderByDescending(s => s.Remarks);
                break;

            case "Remarks_asc":
                Query = Query.OrderBy(s => s.Remarks);
                break;

            default:      // Name ascending
                Query = Query.OrderBy(s => s.TimesheetID);
                break;
            }

            if (command == "Export")
            {
                GridView  gv = new GridView();
                DataTable dt = new DataTable();
                dt.Columns.Add("Timesheet I D", typeof(string));
                dt.Columns.Add("Employee I D", typeof(string));
                dt.Columns.Add("Project I D", typeof(string));
                dt.Columns.Add("Entry Date", typeof(string));
                dt.Columns.Add("Start Time", typeof(string));
                dt.Columns.Add("End Time", typeof(string));
                dt.Columns.Add("Tot Time", typeof(string));
                dt.Columns.Add("Remarks", typeof(string));
                foreach (var item in Query)
                {
                    dt.Rows.Add(
                        item.TimesheetID
                        , item.Employee.FirstName
                        , item.Project.ProjectName
                        , item.EntryDate
                        , item.StartTime
                        , item.EndTime
                        , item.TotTime
                        , item.Remarks
                        );
                }
                gv.DataSource = dt;
                gv.DataBind();
                ExportData(Export, gv, dt);
            }

            int pageNumber = (page ?? 1);
            int?pageSZ     = (Convert.ToInt32(Session["PageSize"]) == 0 ? 5 : Convert.ToInt32(Session["PageSize"]));

            return(View(Query.ToPagedList(pageNumber, (pageSZ ?? 5))));
        }
예제 #13
0
        /// <summary>
        /// Function to populate time sheet details of selected employee
        /// </summary>
        private void populateTimesheetDetails(DateTime startDate, DateTime endDate, string employeeId)
        {
            EmployeeViewModel objEmployeeService = new EmployeeViewModel();

            Task.Run(() => objEmployeeService.LoadDetails(startDate, endDate, employeeId));
            Thread.Sleep(1000);
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Task");
            //Populating column name with week days dynamically
            for (int j = 1; j <= 7; j++)
            {
                dataTable.Columns.Add(startDate.Date.AddDays(j).DayOfWeek.ToString(), typeof(int));
            }
            List <Tasks> taskLst = EmployeeViewModel.taskList;

            //Populating total in task list as last column
            taskLst.Insert(EmployeeViewModel.taskList.Count, new Tasks {
                Id = 0, Description = "Total", Name = "Total"
            });
            int sum = 0;

            foreach (var obj in taskLst)
            {
                DataRow dr = dataTable.NewRow();
                for (int l = 1; l <= 7; l++)
                {
                    if (obj.Name == "Total")
                    {
                        //Adding all efforts on a single day
                        dr[l] = dataTable.AsEnumerable().Sum(r => r.Field <int>(startDate.Date.AddDays(l).DayOfWeek.ToString()));
                        sum   = sum + Convert.ToInt32(dr[l]);
                    }
                    else
                    {
                        if (objEmployeeService.timesheetList != null)
                        {
                            //getting no of hours from db if it is already inserted
                            TimesheetData isExist = objEmployeeService.timesheetList.Find(x => x.workingDay.ToString("dd/MM/yyyy") == startDate.Date.AddDays(l).ToString("dd/MM/yyyy") && x.TaskId.ToString() == obj.Id.ToString());
                            if (isExist == null)
                            {
                                dr[l] = 0;
                            }
                            else
                            {
                                dr[l] = isExist.NoofHrs;
                            }
                        }
                        else
                        {
                            dr[l] = 0;
                        }
                    }
                }
                dr[0] = obj.Name;
                dataTable.Rows.Add(dr);
            }
            //getting average effort in a week
            lblAverage.Content           = sum / 1560;
            lnkBackward.CommandParameter = startDate.ToShortDateString();
            lnkForward.CommandParameter  = startDate.ToShortDateString();
            gdDetails.ItemsSource        = dataTable.DefaultView;
        }