public bool AbscenseUser(AbscenseViewModel abscenseModel) //From Staff Document { using (IDbConnection dbConnection = Connection) { string sQuery = @" if exists (select * from Abscense where StaffID = @StaffID AND Convert(Date,@AbsentStart) = Convert(Date,AbsentStart)) update Abscense set ApplicationType=@ApplicationType,Status=@Status,DateModified=@DateModified,AbsentStart=@AbsentStart,AbsentEnd=@AbsentEnd,AbsentReason=@AbsentReason,AbsentReason2=@AbsentReason2, Destination=(Select top 1 Destination from Position t2 Join PositionAssign t1 on @StaffID = t1.StaffID Where t2.MPLID=t1.MPLID ),JobTitle=(Select top 1 JobTitle from Position t2 Join PositionAssign t1 on @StaffID = t1.StaffID Where t2.MPLID=t1.MPLID ) Where StaffID=@StaffID AND Convert(Date,@AbsentStart) = Convert(Date,AbsentStart); else Insert Into Abscense (StaffID, DateModified,AbsentStart, AbsentEnd, AbsentReason, AbsentReason2,ApplicationType,Status,Destination,JobTitle) Values (@StaffID, @DateModified,@AbsentStart, @AbsentEnd, @AbsentReason, @AbsentReason2,@ApplicationType,@Status,(Select top 1 Destination from Position t2 Join PositionAssign t1 on @StaffID = t1.StaffID Where t2.MPLID=t1.MPLID Order by t1.StartDate ),(Select top 1 JobTitle from Position t2 Join PositionAssign t1 on @StaffID = t1.StaffID Where t2.MPLID=t1.MPLID Order by t1.StartDate )) "; dbConnection.Open(); try { dbConnection.Execute(sQuery, abscenseModel); return(true); } catch (Exception e) { Console.Write(e); return(false); } finally { } } }
public void Add(AbscenseViewModel add) { //if (CheckAssign(assignation) == true) //{ using (var connection = new SqlConnection(connectionString)) { var sql = @" if exists (select * from Abscense where StaffID = @StaffID and AND (Convert(Date,@AbsentStart) = Convert(Date,AbsentStart) ) update Abscense set ApplicationType=@ApplicationType,Status='Received',DateModified=@DateModified,AbsentStart=@AbsentStart,AbsentEnd=@AbsentEnd,AbsentReason=@AbsentReason,AbsentReason2=@AbsentReason2 Where StaffId=@StaffID; else Insert Into Abscense (StaffID, DateModified,AbsentStart, AbsentEnd, AbsentReason, AbsentReason2,ApplicationType,Status) Values (@StaffID, @DateModified,@AbsentStart, @AbsentEnd, @AbsentReason, @AbsentReason2,@ApplicationType,'Received')"; connection.Execute(sql, new { add.ApplicationType, add.StaffID, add.Status, add.DateModified, add.AbsentStart, add.AbsentEnd, add.AbsentReason2, add.AbsentReason }); } //} }
public bool AbscenseUser([FromBody] AbscenseViewModel model) { DateTime?ParsedAbsentStart = model.AbsentStart; DateTime TodayDate = DateTime.Now; UserModel UserName = _userRepo.GetUser(); if (ParsedAbsentStart <= TodayDate) { // ok this is a full abscense with status change in Staff the full Monty var res = _abscenseRepo.AbscenseUser(model); var res2 = _abscenseRepo.UpdateUser(model.StaffID); if (res) { if (res2) { var History = new HistoryModel(); // Add to History all actions of relevancy { History.StaffID = model.StaffID; History.HistoryDate = DateTime.UtcNow; History.HistoryAction = "LEAVE OF ABSENCE"; History.HistoryLocation = "Some Destínation"; History.ApplicationType = "Abscense"; History.DateModified = DateTime.UtcNow; History.Status = "Received"; //History.HistoryWho = System.Security.Principal.WindowsIdentity.GetCurrent().Name; History.HistoryWho = UserName.UserName; }; _historyRepo.UpdateHistoryAbscense(History); _abscenseRepo.DeleteUserInPosAssign(model.StaffID); return(true); } } } else { // just create dates and abscense entry the not so full Monty var res1 = _abscenseRepo.AbscenseUser(model); if (res1) { return(true); } } return(false); }