/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="activityId"></param> /// <param name="employeeName"></param> /// <returns></returns> public bool InsertTimeOut(ClockOutQueryModel clockOut) { DailyTimeOut newRecord = new DailyTimeOut(); try { using (TimeInEntities context = new TimeInEntities()) { newRecord.EmployeeId = clockOut.UserId; newRecord.ActivityCd = clockOut.ActivityId; newRecord.TimeOutDttm = clockOut.ClockOutDateTime; newRecord.IsActive = true; newRecord.CreateDttm = DateTime.Now; newRecord.CreateUserId = clockOut.UserName; newRecord.UpdateDttm = DateTime.Now; newRecord.UpdateUserId = clockOut.UserName; context.DailyTimeOuts.Add(newRecord); context.SaveChanges(); } } catch (Exception ex) { return(false); } return(true); }
/// <summary> /// Updates existing Activity. /// </summary> /// <param name="activityId"></param> /// <param name="newActivity"></param> /// <returns></returns> public string UpdateActivity(int activityId, Activity newActivity) { Activity activityQuery = new Activity(); try { using (TimeInEntities context = new TimeInEntities()) { activityQuery = context.Activities .Where(x => x.ActivityId == activityId && x.IsActive == true).FirstOrDefault(); activityQuery.ActivityNm = newActivity.ActivityNm; activityQuery.UpdateDttm = DateTime.Now; context.Activities.Attach(activityQuery); context.SaveChanges(); } } catch (Exception ex) { return(ex.Message); } return("Activity updated."); }
/// <summary> /// /// </summary> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="userName"></param> /// <returns></returns> public string InsertNewUser(string firstName, string lastName, string userName) { User newUser = new User(); try { using (TimeInEntities context = new TimeInEntities()) { newUser.FirstName = firstName; newUser.LastName = lastName; newUser.IsActive = true; newUser.UserName = userName; newUser.UserPassword = "******"; newUser.CreateDttm = DateTime.Now; newUser.CreateUserId = "Admin"; newUser.UpdateDttm = DateTime.Now; newUser.UpdateUserId = "Admin"; context.Users.Add(newUser); context.SaveChanges(); } } catch (Exception ex) { return(ex.Message); } return("New user inserted."); }
/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="newPassword"></param> /// <returns></returns> public string UpdatePassword(int userId, string newPassword) { User userQuery = new User(); try { using (TimeInEntities context = new TimeInEntities()) { userQuery = context.Users.Where(x => x.UserKey == userId && x.IsActive == true).FirstOrDefault(); userQuery.UserPassword = newPassword; userQuery.UpdateDttm = DateTime.Now; userQuery.UpdateUserId = userQuery.UserName; context.Users.Attach(userQuery); context.Entry(userQuery).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } catch (Exception ex) { return(ex.Message); } return("User record updated."); }
/// <summary> /// Inserts new Acitivity to the database. /// </summary> /// <param name="newActivity"></param> /// <returns></returns> public string InsertActivity(Activity newActivity) { try { using (TimeInEntities context = new TimeInEntities()) { context.Activities.Add(newActivity); context.SaveChanges(); } } catch (Exception ex) { return(ex.Message); } return("Activity saved."); }
/// <summary> /// Deactivates specified query. Application will not do hard delete. /// </summary> /// <param name="activityId"></param> /// <returns></returns> public string DeleteActivity(int activityId) { try { using (TimeInEntities context = new TimeInEntities()) { var activityQuery = context.Activities .Where(x => x.ActivityId == activityId).FirstOrDefault(); activityQuery.IsActive = false; context.Activities.Attach(activityQuery); context.SaveChanges(); } } catch (Exception ex) { return(ex.Message); } return("Activity deleted."); }