Пример #1
0
        [HttpPost(nameof(AbscenseUserSelect))]   //From View
        public bool AbscenseUserSelect([FromBody] AbscenseModel model)
        {
            DateTime?ParsedAbsentStart = model.AbsentStart;
            DateTime TodayDate         = DateTime.Now;


            foreach (string StaffID in model.StaffID)
            {
                if (ParsedAbsentStart <= TodayDate)
                {
                    //  ok  this is a full abscense with status change in Staff  the full Monty
                    var res1 = _abscenseRepo.AbscenseUser(model, StaffID);

                    var res2 = _abscenseRepo.UpdateUser(StaffID);
                    var res3 = _abscenseRepo.DeleteUserInPosAssign(StaffID);


                    if (res1)
                    {
                        if (res2)
                        {
                            if (res3)
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    // just create dates and abscense entry   the not so full Monty
                    var res1 = _abscenseRepo.AbscenseUser(model, StaffID);


                    if (res1)
                    {
                        return(true);
                    }
                }
            }

            return(false);

            //var res = _abscenseRepo.UpdateUser(model.AbsentReason);
            ////var res = _resignRepo.DeleteUserInPosAssign(resignModel.StaffID);

            // return res;
        }
Пример #2
0
        public bool AbscenseUser(AbscenseModel abscenseModel, string StaffIDSingle)   //From SelectedStaff
        {
            using (IDbConnection dbConnection = Connection)
            {
                //DateModified = @DateModified

                //(StaffID, DateModified, AbsentStart, AbsentEnd, AbsentReason, AbsentReason2)
                //  Values
                //  (@StaffID, @DateModified, @AbsentStart, @AbsentEnd, @AbsentReason, @AbsentReason2)";



                string sQuery = @" if exists (select * from Abscense  where StaffID = @StaffIDSingle  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=@StaffIDSingle AND (Convert(Date,@AbsentStart) = Convert(Date,AbsentStart);
                            else Insert Into Abscense
                            (StaffID, DateModified,AbsentStart, AbsentEnd, AbsentReason, AbsentReason2,ApplicationType,Status)
                            Values
                           (@StaffIDSingle, @DateModified,@AbsentStart, @AbsentEnd, @AbsentReason, @AbsentReason2,@ApplicationType,'Received')";

                dbConnection.Open();
                try
                {
                    dbConnection.Execute(sQuery, new
                    {
                        abscenseModel.AbsentStart,
                        abscenseModel.DateModified,
                        abscenseModel.AbsentEnd,
                        abscenseModel.AbsentReason,
                        abscenseModel.AbsentReason2,
                        abscenseModel.ApplicationType,
                        abscenseModel.Status,
                        StaffIDSingle
                    });
                    return(true);
                }
                catch (Exception e)
                {
                    Console.Write(e);
                    return(false);
                }
                finally
                {
                }
            }
        }