Esempio n. 1
0
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = this.GridView1.Rows[e.RowIndex];

            var totalHours = 0;

            for (int i = 2; i < row.Cells.Count; i++)
            {
                var hours = ((TextBox)row.Cells[i].Controls[0]).Text;
                if (!string.IsNullOrWhiteSpace(hours))
                {
                    totalHours += Convert.ToInt32(hours);
                }
            }

            if (totalHours > 24)
            {
                e.Cancel = true;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('total hours are more than 24 hours.');", true);
                return;
            }

            for (int i = 2; i < row.Cells.Count; i++)
            {
                var timeLog     = ((TextBox)row.Cells[i].Controls[0]).Text;
                var day         = ((TextBox)row.Cells[1].Controls[0]).Text;
                var projectName = ((DataControlFieldCell)GridView1.HeaderRow.Cells[i]).ContainingField.HeaderText;

                timeLogModule.UpdateTimeLog(projectName, timeLog, day, this.Session["EmpNr"] as string);
            }

            this.GridView1.EditIndex  = -1;
            this.Session["GridTable"] = null;
            this.BindGrid();
        }
Esempio n. 2
0
        public HttpResponseMessage AddTimeLog(HttpRequestMessage request)
        {
            try
            {
                if (request.Content.Headers.ContentType.MediaType != "application/json")
                {
                    return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
                }

                var jsonData = request.Content.ReadAsStringAsync().Result;
                var data     = JObject.Parse(jsonData);

                var logs = new List <Log>();
                foreach (var jLog in ((JToken)data["logs"]).ToList())
                {
                    JToken logEntry = jLog["log"];

                    var log = new Log()
                    {
                        WorkDay = DateTime.Parse((string)logEntry["workday"]),
                        TimeLog = ((JToken)logEntry["timelogs"]).ToDictionary(x => (string)x["project"], y => (int)y["Hours"])
                    };

                    if (log.TimeLog.Sum(x => x.Value) > 24)
                    {
                        return new HttpResponseMessage(HttpStatusCode.BadRequest)
                               {
                                   Content = new StringContent($"Total time exceeds 24 hours for workday: {log.WorkDay.ToShortDateString()}")
                               }
                    }
                    ;

                    logs.Add(log);
                }

                var empNr = Thread.CurrentPrincipal.Identity.Name;

                foreach (var log in logs)
                {
                    foreach (var timeLog in log.TimeLog)
                    {
                        try
                        {
                            timeLogModule.UpdateTimeLog($"{timeLog.Key}", timeLog.Value.ToString(), log.WorkDay.ToShortDateString(), empNr);
                        }
                        catch (Exception e)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                            {
                                Content = new StringContent($"Error adding log for project: {timeLog.Key}, for workday: {log.WorkDay}")
                            });
                        }
                    }
                }

                return(new HttpResponseMessage(HttpStatusCode.Accepted));
            }
            catch (Exception e)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
        public HttpResponseMessage AddTimeLog(HttpRequestMessage request)
        {
            try
            {
                if (request.Content.Headers.ContentType.MediaType != "application/json")
                {
                    return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
                }

                var jsonData = request.Content.ReadAsStringAsync().Result;
                var data     = JArray.Parse(jsonData);

                var logs = new List <Log>();
                foreach (var jToken in data)
                {
                    var log = new Log()
                    {
                        WorkDay = DateTime.Parse((string)jToken["WorkDay"]),
                        TimeLog = jToken.Children().Select(x => (JProperty)x)
                                  .Where(y => y.Name != "WorkDay" && !string.IsNullOrWhiteSpace((string)y.Value))
                                  .ToDictionary(project => (string)project.Name, hours => (int)hours.Value)
                    };

                    if (log.TimeLog.Sum(x => x.Value) > 24)
                    {
                        return new HttpResponseMessage(HttpStatusCode.BadRequest)
                               {
                                   Content = new StringContent($"Total time exceeds 24 hours for workday: {log.WorkDay.ToShortDateString()}")
                               }
                    }
                    ;

                    logs.Add(log);
                }

                var empNr = Thread.CurrentPrincipal.Identity.Name;

                foreach (var log in logs)
                {
                    foreach (var timeLog in log.TimeLog)
                    {
                        try
                        {
                            BasicValidator.ValidateAsNonSpacedString(timeLog.Key, errorLogger);
                            timeLogModule.UpdateTimeLog($"{timeLog.Key}", timeLog.Value.ToString(), log.WorkDay.ToShortDateString(), empNr);
                        }
                        catch (Exception e)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                            {
                                Content = new StringContent($"Error adding log for project: {timeLog.Key}, for workday: {log.WorkDay}")
                            });
                        }
                    }
                }

                return(new HttpResponseMessage(HttpStatusCode.Accepted));
            }
            catch (Exception e)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }