public ActionResult CreateTimeTrack(FormCollection collection)
        {
            UserTimeTrackHistoryMapped utth = new UserTimeTrackHistoryMapped(getCompanyId());
            //var userList = MembershipUserExtended.GetFullNameUserNameList();
            string userName = collection["UserName"];
            utth.UserName = userName;

            DateTime clockInDt;
            DateTime clockOutDt;
            if (DateTime.TryParse(collection["ClockInTime"], out clockInDt) && DateTime.TryParse(collection["ClockOutTime"], out clockOutDt))
            {
                if (clockOutDt.TimeOfDay.CompareTo(clockInDt.TimeOfDay) != -1) // if clock out time is earlier than clock in time than error
                {
                    utth.ClockInTime = string.Format("{0:t}", clockInDt);
                    utth.ClockOutTime = string.Format("{0:t}", clockOutDt);
                    utth.UserId = Convert.ToInt32(userName);
                    //utth.UserId = ((HBS.WebPortal.Models.User)Session["user"]).userid;
                    utth.CreatedBy = ((HBS.WebPortal.Models.User)Session["user"]).UserName;
                    utth.CreatedDate = HBS.Data.Entities.SchedulingTimeTracking.Infrastructure.WebHelpers.GetCurrentDateTimeByTimeZoneId(System.Configuration.ConfigurationManager.AppSettings["UserTimeZoneId"]);
                    utth.IsDeleted = false;
                    var tth = utth.Get(utth.Save(),getCompanyId());
                    tth.UserName = userName;
                    ViewBag.Message = "Record inserted successfully.";
                    return View(tth);
                }
                else
                {
                    ViewBag.Message = "Clock Out time can not be earlier than Clock In time.";
                    return View(utth);
                }
            }
            else
            {
                ViewBag.Message = "Not a valid Clock In/Out time, please make sure time is in correct format.";
                return View(utth);
            }
            //ViewBag.Message = "Error inserting record.";
            //return View(new UserTimeTrackHistoryMapped());
        }
 public UserTimeTrackHistoryMapped Get(int timeTrackId, int companyId)
 {
     using (var dbContext = new SchTimeTrackingEntities())
     {
         var userTimeTrackRecord =
             dbContext.UserTimeTrackHistories.FirstOrDefault(c => c.TimeTrackId == timeTrackId);
         if (userTimeTrackRecord != null)
         {
             var timeTrackMappedRecord = new UserTimeTrackHistoryMapped(companyId)
                 {
                     TimeTrackId = userTimeTrackRecord.TimeTrackId,
                     UserName = userTimeTrackRecord.UserName,
                     UserId = userTimeTrackRecord.UserId,
                     ClockInTime = userTimeTrackRecord.ClockInTime,
                     ClockOutTime = userTimeTrackRecord.ClockOutTime,
                     StampDate = userTimeTrackRecord.StampDate,
                     IsDeleted = userTimeTrackRecord.IsDeleted,
                     CreatedBy = userTimeTrackRecord.CreatedBy,
                     CreatedDate = userTimeTrackRecord.CreatedDate
                 };
             return timeTrackMappedRecord;
         }
         return new UserTimeTrackHistoryMapped(companyId);
     }
 }