public static string ChangeProgress(string jsonString)
        {
            var cdb = new ConnectDB("Database1");

            if (jsonString == "")
            {
                return("nil");
            }
            var receivedData = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString);

            try
            {
                var participant = new ParticipantModel
                {
                    ProgressId      = int.Parse(receivedData["progressId"]),
                    ParticipantName = receivedData["participantName"],
                    CurrentProgress = int.Parse(receivedData["currentProgress"])
                };
                var password = receivedData["progPassword"];
                if (cdb.IsCorrectPassword(participant, password))
                {
                    cdb.ChangeProgress(participant);
                    return("success");
                }
                return("wrongPassword");
            }
            catch (Exception ex)
            {
                var thisPage = new GetJsonString();
                thisPage.WriteErrorLog(ex.Message);
                return("error");
            }
        }
Example #2
0
        public static string GetTasks(string strProgressId)
        {
            var cdb = new ConnectDB("Database1");

            try
            {
                int    progressId = int.Parse(strProgressId);
                var    result     = cdb.GetTasks(progressId);
                string json       = JsonConvert.SerializeObject(result, Formatting.Indented);
                return(json);
            }
            catch (Exception ex)
            {
                var thisPage = new GetJsonString();
                thisPage.WriteErrorLog(ex.Message);
                return("error");
            }
        }
        public static string SetNewProgress(string jsonString)
        {
            var cdb = new ConnectDB("Database1");

            if (jsonString == "")
            {
                return("failed");
            }
            var receivedData = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString);

            try
            {
                var progress = new ProgressModel
                {
                    UserId             = receivedData["userId"],
                    Title              = receivedData["title"],
                    DateTimeRegistered = DateTime.Now,
                    NumberOfTask       = int.Parse(receivedData["numberOfTask"]),
                    Password           = receivedData["password"]
                };
                var tasks = new List <TaskModel>();
                for (int i = 1; i <= progress.NumberOfTask; i++)
                {
                    tasks.Add(new TaskModel {
                        Task = receivedData["task" + i.ToString()]
                    });
                }


                if (cdb.SetProgress(progress, tasks))
                {
                    return("success");
                }
                return("failed");
            }
            catch (Exception ex)
            {
                var thisPage = new GetJsonString();
                thisPage.WriteErrorLog(ex.Message);
                return("error");
            }
        }
Example #4
0
 public static string GetRegisteredProgresses(string userId)
 {
     try
     {
         var cdb    = new ConnectDB("Database1");
         var result = cdb.GetAProgress(userId);
         if (result.Count == 0)
         {
             return("nil");
         }
         // シリアライズ
         string json = JsonConvert.SerializeObject(result, Formatting.Indented);
         return(json);
     }
     catch (Exception ex)
     {
         var thisPage = new GetJsonString();
         thisPage.WriteErrorLog(ex.Message);
         return("error");
     }
 }
        public static string SetNewParticipant(string jsonString)
        {
            var cdb = new ConnectDB("Database1");

            if (jsonString == "")
            {
                return("error");
            }
            var receivedData = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString);

            try
            {
                var participant = new ParticipantModel
                {
                    ProgressId      = int.Parse(receivedData["progressId"]),
                    ParticipantName = receivedData["name"],
                    CurrentProgress = 0
                };
                var password = receivedData["password"];
                if (!cdb.IsCorrectPassword(participant, password))
                {
                    return("wrongPassword");
                }
                if (cdb.IsExistSameName(participant))
                {
                    return("sameNameExisted");
                }

                cdb.SetParticipant(participant);

                return("registeredSuccess");
            }
            catch (Exception ex)
            {
                var thisPage = new GetJsonString();
                thisPage.WriteErrorLog(ex.Message);
                return("error");
            }
        }