// Obtain of time public bool ObtainTime(ObtainTimeContract obtainTime) { using (var db = new TimeManagerContext()) { try { var currentRecords = from oT in db.ElapsedTimes where oT.ProjectId == obtainTime.ProjectId && oT.EmployeeId == obtainTime.EmployeeId select oT; if (currentRecords.Count() > 0) { foreach (var time in currentRecords) { time.Time += obtainTime.HoursAmount; } } else { db.ElapsedTimes.Add(new ElapsedTime { Time = obtainTime.HoursAmount, ProjectId = obtainTime.ProjectId, EmployeeId = obtainTime.EmployeeId }); } db.SaveChanges(); } catch (Exception ex) { // throw new FaultException<string> Console.WriteLine(ex.Message); } } return(true); }
// Obtain time public static bool ObtainTime(int hoursAmount, int employeeId, int projectId) { ObtainTimeContract obtainTime = new ObtainTimeContract { HoursAmount = hoursAmount, EmployeeId = employeeId, ProjectId = projectId }; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ObtainTimeContract)); MemoryStream mem = new MemoryStream(); ser.WriteObject(mem, obtainTime); string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length); WebClient webClient = new WebClient(); string serviceURL = string.Format(serverUri + "ObtainTime"); //Post webClient.Headers["Content-type"] = "application/json"; webClient.Encoding = Encoding.UTF8; string dataAnswer = webClient.UploadString(serviceURL, "POST", data); //Answer return(dataAnswer == "true" ? true : false); }