Beispiel #1
0
        public static bool UpdatePresent(PresentDay presentDay)
        {
            PresentDay currentPresentDay = GetPresentById(presentDay.IdPresentDay);
            TimeSpan   t = DateTime.Parse(presentDay.TimeEnd.ToString("yyyy-MM-dd HH:mm:ss")) - currentPresentDay.TimeBegin;

            double addedHours = t.TotalHours;

            string query = $"UPDATE task.PresentDay SET EndHour='{presentDay.TimeEnd.ToString("yyyy-MM-dd HH:mm:ss")}',TotalHours={addedHours} WHERE IdPresentDay={presentDay.IdPresentDay}";

            if (DBAccess.RunNonQuery(query) == 1)
            {
                BOL.Models.Task currentTask = LogicTask.GetTaskByIdProjectAndIdUser(currentPresentDay.UserId, currentPresentDay.ProjectId);
                currentTask.GivenHours += (decimal)addedHours;
                if (LogicTask.UpdateTask(currentTask))
                {
                    User Currentuser = LogicManager.GetUserDetails(currentPresentDay.UserId);
                    Currentuser.NumHoursWork += (decimal)addedHours;
                    if (LogicManager.UpdateUser(Currentuser))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public HttpResponseMessage Post([FromBody] PresentDay value)
        {
            if (ModelState.IsValid)
            {
                return((LogicPresentDay.AddPresent(value)) ?
                       new HttpResponseMessage(HttpStatusCode.Created) :
                       new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter())
                });
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the user is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter())
            });
        }
Beispiel #3
0
 public static bool updatePresentDay(PresentDay presentDay)
 {
     try
     {
         var httpWebRequest = (HttpWebRequest)WebRequest.Create($@"http://{GlobalProp.URI}api/updatePresentDay");
         httpWebRequest.ContentType = "application/json";
         httpWebRequest.Method      = "PUT";
         using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
         {
             string cardsString = Newtonsoft.Json.JsonConvert.SerializeObject(presentDay, Formatting.None);
             streamWriter.Write(cardsString);
             streamWriter.Flush();
             streamWriter.Close();
         }
         var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
         if (httpResponse.StatusDescription == "OK")
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Update pressent- date time
        /// </summary>
        /// <param name="present">PresentDay contain- idUser, idProject, dateEnd</param>
        /// <returns>bool true- succsess to update, false- failed to update</returns>
        public static bool UpdatePresent(PresentDay present)
        {
            string dateEnd = present.TimeEnd.ToLocalTime().ToString("yyyy-MM-dd hh:mm:ssss");
            string query   = $"set @id=0;select max(presentDayId) into @id from presentday where id = {present.UserId} and projectId ={present.ProjectId}; UPDATE `managertasks`.`presentday`SET`timeEnd` = '{dateEnd}' WHERE presentDayId = @id and id ={present.UserId} and projectId = {present.ProjectId}";

            return(DBAccess.RunNonQuery(query) != null);
        }
Beispiel #5
0
 /// <summary>
 /// AddPresentDay
 /// </summary>
 /// <param name="presentDay">presentDay contain -idUser, idProject and dateStart</param>
 /// <returns>bool true- succses update, false- failed update</returns>
 public static bool UpdatePresentDay(PresentDay presentDay)
 {
     try
     {
         var httpWebRequest = (HttpWebRequest)WebRequest.Create($@"{GlobalProp.URI}api/updatePresentDay");
         httpWebRequest.ContentType = "application/json";
         httpWebRequest.Method      = "PUT";
         using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
         {
             string cardsString = Newtonsoft.Json.JsonConvert.SerializeObject(presentDay, Formatting.None);
             streamWriter.Write(cardsString);
             streamWriter.Flush();
             streamWriter.Close();
         }
         var httpResponse   = (HttpWebResponse)httpWebRequest.GetResponse();
         var responseString = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();
         BaseService.GetMessage(responseString, "succses");
         return(true);
     }
     catch (WebException ex)
     {
         BaseService.GetErrorsFromServer(ex);
         return(false);
     }
     catch
     {
         BaseService.GetMessage("failed to set pressent", "failed");
         return(false);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Add pressent
        /// </summary>
        /// <param name="presentDay">presentDay- contain idUser, idProject, dateBegin </param>
        /// <returns></returns>
        public static bool AddPresent(PresentDay presentDay)
        {
            string dateBegin = presentDay.TimeBegin.ToLocalTime().ToString("yyyy-MM-dd hh:mm:ssss");
            string dateEnd   = presentDay.TimeEnd.ToLocalTime().ToString("yyyy-MM-dd hh:mm:ssss");
            string query     = $"INSERT INTO `managertasks`.`PresentDay`(`timeBegin`,`timeEnd`,`projectId`,`id`) VALUES('{dateBegin}','{dateEnd}',{presentDay.ProjectId},{presentDay.UserId}); ";

            return(DBAccess.RunNonQuery(query) == 1);
        }
Beispiel #7
0
        //end timer to finish work
        private bool EndPressent()
        {
            timerPressent.Enabled = false;
            PresentDay p = new PresentDay();

            p.UserId    = GlobalProp.CurrentUser.UserId;
            p.ProjectId = (listProjectsWorker.SelectedItem.Tag as Project).ProjectId;
            p.TimeEnd   = DateTime.Now;
            return(PresentDayRequests.UpdatePresentDay(p));
        }
Beispiel #8
0
 private void btn_login_Click(object sender, EventArgs e)
 {
     presentDay = new PresentDay()
     {
         UserId    = worker.UserId,
         ProjectId = currentProject.ProjectId,
         TimeBegin = DateTime.Parse(txt_clock.Text),
     };
     cmb_myProjects.Enabled = false;
     PresentDayRequests.AddPresent(presentDay);
     btn_login.Enabled  = false;
     btn_logout.Enabled = true;
 }
 public HttpResponseMessage Put([FromBody] PresentDay value)
 {
     if (ModelState.IsValid)
     {
         return((LogicPresentDay.UpdatePresent(value)) ?
                new HttpResponseMessage(HttpStatusCode.OK) :
                new HttpResponseMessage(HttpStatusCode.BadRequest)
         {
             Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter())
         });
     }
     ;
     return(Request.CreateResponse(HttpStatusCode.BadRequest, BaseLogic.GetErorList(ModelState.Values)));
 }
        public static bool AddPresent(PresentDay NewpresentDay)
        {
            //Post Request for Register
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:61309/api/PresentDay/AddPresent");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string presentDay = JsonConvert.SerializeObject(NewpresentDay, Formatting.None);

                streamWriter.Write(presentDay);
                streamWriter.Flush();
                streamWriter.Close();
            }
            try
            {
                //Gettting response
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                //Reading response
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    string result = streamReader.ReadToEnd();
                    //If AddPresent succeeded
                    if (httpResponse.StatusCode == HttpStatusCode.Created)
                    {
                        if (!int.TryParse(result, out idPresentDay))
                        {
                            return(false);
                        }
                        return(true);
                    }
                    return(false);
                }
            }
            catch (WebException ex)
            {
                using (var stream = ex.Response.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        //Printing the matchung errors:
                        MessageBox.Show(reader.ReadToEnd());
                    }
                return(false);
            }
        }
Beispiel #11
0
        public static int AddPresent(PresentDay presentDay)
        {
            //TODO:לעדכן את סך השעות שהעובד עבד
            string query = $"INSERT INTO `task`.`PresentDay`(`IdProject`,`IdUser`,`startHour`,`EndHour`,`Totalhours`) VALUES({presentDay.ProjectId},{presentDay.UserId},'{presentDay.TimeBegin.ToString("yyyy-MM-dd HH:mm:ss tt")}','{presentDay.TimeEnd.ToString("yyyy-MM-dd HH:mm:ss")}',{presentDay.sumHoursDay}); ";

            if (DBAccess.RunNonQuery(query) == 1)
            {
                try {
                    return(GetPresent(presentDay.UserId, presentDay.ProjectId, presentDay.TimeBegin).IdPresentDay);
                }
                catch
                {
                    return(0);
                }
            }
            return(0);
        }
Beispiel #12
0
        private void btn_end_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            PresentDay p = new PresentDay();

            p.UserId    = GlobalProp.CurrentUser.UserId;
            p.ProjectId = (cmbx_projects.SelectedItem as Project).ProjectId;
            p.TimeEnd   = DateTime.Now;

            if (PresentDayRequests.updatePresentDay(p))
            {
                MessageBox.Show("End");
            }
            else
            {
                MessageBox.Show("Error");
            }
        }
        public static bool UpdatePresentDay(PresentDay presentDay)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create($@"http://localhost:61309/api/PresentDay/UpdatePresentDay");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "PUT";
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                dynamic currentPresentDay        = presentDay;
                string  currentPresentNameString = Newtonsoft.Json.JsonConvert.SerializeObject(currentPresentDay, Formatting.None);
                streamWriter.Write(currentPresentNameString);
                streamWriter.Flush();
                streamWriter.Close();
            }
            //Get response
            try
            {
                //Gettting response
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                //Reading response
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    string result = streamReader.ReadToEnd();
                    //If AddPresent succeeded
                    if (httpResponse.StatusCode == HttpStatusCode.OK)
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            catch (WebException ex)
            {
                using (var stream = ex.Response.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        //Printing the matchung errors:
                        MessageBox.Show(reader.ReadToEnd());
                    }
                return(false);
            }
        }
Beispiel #14
0
        public static bool AddPresent(PresentDay NewpresentDay)
        {
            try
            {
                //Post Request for Register
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://localhost:61309/api/AddPresent");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string user = JsonConvert.SerializeObject(NewpresentDay, Formatting.None);

                    streamWriter.Write(user);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                //Gettting response
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                //Reading response
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    string result = streamReader.ReadToEnd();
                    //If Register succeeded
                    if (httpResponse.StatusCode == HttpStatusCode.Created)
                    {
                        idPresentDay = int.Parse(result);


                        return(true);
                    }
                    //Printing the matching error
                }
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show("failed to add");
            }
            return(false);
        }
Beispiel #15
0
        public HttpResponseMessage UpdatePresentDay([FromBody] PresentDay value)
        {
            if (ModelState.IsValid)
            {
                return(LogicPresentDay.UpdatePresent(value) ?
                       Request.CreateResponse(HttpStatusCode.OK) :
                       Request.CreateResponse(HttpStatusCode.BadRequest, "Can not update in DB"));
            }
            ;

            List <string> ErrorList = new List <string>();

            //if the code reached this part - the user is not valid
            foreach (var item in ModelState.Values)
            {
                foreach (var err in item.Errors)
                {
                    ErrorList.Add(err.ErrorMessage);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest, ErrorList));
        }
Beispiel #16
0
        private void btn_start_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            //btn_end.Visible = true;
            //btn_start.Visible = false;
            PresentDay p = new PresentDay();

            p.UserId    = GlobalProp.CurrentUser.UserId;
            p.ProjectId = (cmbx_projects.SelectedItem as Project).ProjectId;
            DateTime d = DateTime.Now;

            p.TimeBegin = d;
            p.TimeEnd   = d;

            if (PresentDayRequests.addPresentDay(p))
            {
                MessageBox.Show("Start");
            }
            else
            {
                MessageBox.Show("Error");
            }
        }
Beispiel #17
0
        public static bool addPresentDay(PresentDay presentDay)
        {
            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create($"{GlobalProp.URI}api/AddPresent");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string NewUserString = Newtonsoft.Json.JsonConvert.SerializeObject(presentDay, Formatting.None);
                    streamWriter.Write(NewUserString);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                //Gettting response
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                //Reading response
                using (var streamReader = new System.IO.StreamReader(httpResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                {
                    string result = streamReader.ReadToEnd();
                    //If Login succeeded
                    if (result != null)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }