public ActionResult Create(UserTimeTrackHistoryMapped utth,FormCollection collection)
        {
            var userList = MembershipUserExtended.GetFullNameUserNameList();
            string userName=collection["UserName"];
            if (userList.ContainsValue(userName))
            {
                utth.UserName = userName;

                DateTime clockInDt;
                DateTime clockOutDt;
                if (DateTime.TryParse(utth.ClockInTime, out clockInDt) && DateTime.TryParse(utth.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 = MembershipUserExtended.GetUserIdByUserName(userName);
                        utth.CreatedBy = LoggedInUserName;
                        utth.CreatedDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]);
                        utth.IsDeleted = false;
                        var tth = utth.Get(utth.Save());
                        tth.UserName = userList.FindKeyByValue(userName);
                        ViewBag.Message = "Record inserted successfully.";
                        return View(tth);
                    }
                    ViewBag.Message = "Clock Out time can not be earlier than Clock In time.";
                    return View(utth);
                }
                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());
        }
Esempio n. 2
0
 public UserTimeTrackHistoryMapped Get(int timeTrackId)
 {
     using (var dbContext = new TimeTrackingEntities())
     {
         var userTimeTrackRecord =
             dbContext.UserTimeTrackHistories.FirstOrDefault(c => c.TimeTrackId == timeTrackId);
         if (userTimeTrackRecord != null)
         {
             var timeTrackMappedRecord = new UserTimeTrackHistoryMapped()
             {
                 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());
     }
 }
 public UserTimeTrackHistoryMapped Get(int timeTrackId)
 {
     using (var dbContext = new TimeTrackingEntities())
     {
         var userTimeTrackRecord =
             dbContext.UserTimeTrackHistories.FirstOrDefault(c => c.TimeTrackId == timeTrackId);
         if (userTimeTrackRecord != null)
         {
             var timeTrackMappedRecord = new UserTimeTrackHistoryMapped()
                 {
                     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();
     }
 }