コード例 #1
0
 public ServiceResponse <Data.Models.Program> CreateProgram(Data.Models.Program program)
 {
     try
     {
         _db.Programs.Add(program);
         _db.SaveChanges();
         return(new ServiceResponse <Data.Models.Program>
         {
             IsSuccess = true,
             Message = "New Program Added",
             Time = DateTime.UtcNow,
             Data = program
         });
     }
     catch (Exception e)
     {
         return(new ServiceResponse <Data.Models.Program>
         {
             IsSuccess = false,
             Message = e.StackTrace,
             Time = DateTime.UtcNow,
             Data = null
         });
     }
 }
コード例 #2
0
 public static ProgramModel SerializeProgram(Data.Models.Program program)
 {
     return new ProgramModel
     {
         Id = program.Id,
         Name = program.Name,
         ProgressPercentage = program.ProgressPercentage,
         TotalTask = program.TotalTask,
         TaskComplete = program.TaskComplete,
         Description = program.Description,
         StartDate = program.StartDate,
         EndDate = program.EndDate,
         LastUpdate = program.LastUpdate
     };
 }
コード例 #3
0
        public ServiceResponse <bool> UpdateProgram(Data.Models.Program program)
        {
            var now = DateTime.UtcNow;

            if (program == null)
            {
                return(new ServiceResponse <bool>
                {
                    Time = now,
                    IsSuccess = false,
                    Message = "Program to update not found",
                    Data = false
                });
            }

            try
            {
                _db.Programs.Update(program);

                _db.SaveChanges();
                return(new ServiceResponse <bool>
                {
                    Time = now,
                    IsSuccess = true,
                    Message = "Program description updated!",
                    Data = true
                });
            }
            catch (Exception e)
            {
                return(new ServiceResponse <bool>
                {
                    Time = now,
                    IsSuccess = false,
                    Message = e.StackTrace,
                    Data = false
                });
            }
        }