示例#1
0
        public JsonResult ApproveChange(int changeId, bool approve)
        {
            using (Entity context = new Entity())
            {
                try
                {
                    t_observation_change change = context.t_observation_change.Find(changeId);
                    if (change == null)
                    {
                        throw new ArgumentException("Invalid attachmentId: " + changeId.ToString());
                    }

                    change.approved         = approve;
                    change.updatedby_userid = CurrentUser.Id;
                    change.updated_date     = DateTime.Now;
                    context.SaveChanges();

                    context.Entry(change).Reference(n => n.updatedby).Load();

                    return(Json(new
                    {
                        success = true,
                        Approved = change.approved,
                        UpdatedBy = change.updatedby.full_name,
                        UpdatedOn = change.updated_date.Value.ToString("d")
                    }));
                }
                catch (Exception ex)
                {
                    return(GetJsonResult(ex));
                }
            }
        }
示例#2
0
        public JsonResult EditChange(ObservationChange model)
        {
            using (Entity context = new Entity())
            {
                try
                {
                    t_observation_change change = context.t_observation_change.Find(model.ChangeId);
                    if (change == null)
                    {
                        throw new ArgumentException("Invalid changeId: " + model.ChangeId.ToString());
                    }

                    change.start_date       = model.StartDate;
                    change.description      = model.Description;
                    change.updatedby_userid = CurrentUser.Id;
                    change.updated_date     = DateTime.Now;
                    context.SaveChanges();

                    context.Entry(change).Reference(n => n.updatedby).Load();

                    return(Json(new
                    {
                        success = true,
                        StartDate = change.start_date.ToString("d"),
                        Description = change.description,
                        UpdatedBy = change.updatedby.full_name,
                        UpdatedOn = change.updated_date.Value.ToString("d")
                    }));
                }
                catch (Exception ex)
                {
                    return(GetJsonResult(ex));
                }
            }
        }
示例#3
0
 public CoachReportChange(t_observation_change change)
 {
     Date          = change.start_date;
     IndicatorId   = change.observation.indicator_id;
     IndicatorName = change.observation.indicator.name;
     Change        = change.description;
     CreatedBy     = change.createdby.full_name;
 }
示例#4
0
 public ObservationChange(t_observation_change change)
 {
     ChangeId        = change.observation_change_id;
     ObservationId   = change.observation_id;
     Description     = change.description;
     StartDate       = change.start_date;
     CreatedByUserId = change.createdby_userid;
     CreatedOn       = change.created_date;
     UpdatedByUserId = change.updatedby_userid;
     UpdatedOn       = change.updated_date;
     Approved        = change.approved;
 }
示例#5
0
        private int?UpsertChange(dynamic model)
        {
            // "New" changes are always new (no collisions). Check if "updated" changes
            // exist before updating; if they no longer exist for some reason, re-create.
            t_observation_change entity = null;
            int changeId;

            if (Int32.TryParse(model.ChangeId.ToString(), out changeId))
            {
                entity = Context.t_observation_change.Find(changeId);
            }
            bool isNew = entity == null;

            if (isNew)
            {
                entity = new t_observation_change()
                {
                    observation_id   = model.ObservationId,
                    approved         = false,
                    createdby_userid = CurrentUserId,
                    created_date     = Convert.ToDateTime(model.CreatedOn)
                };
                Context.t_observation_change.Add(entity);
            }
            else
            {
                entity.updatedby_userid = CurrentUserId;
                entity.updated_date     = Convert.ToDateTime(model.UpdatedOn);
            }
            entity.start_date  = Convert.ToDateTime(model.StartDate);
            entity.description = model.Description;
            Context.SaveChanges();

            if (isNew)
            {
                return(entity.observation_change_id);
            }
            else
            {
                return(null);
            }
        }
示例#6
0
 public JsonResult DeleteChange(int changeId)
 {
     using (Entity context = new Entity())
     {
         try
         {
             t_observation_change change = context.t_observation_change.Find(changeId);
             if (change != null)
             {
                 context.t_observation_change.Remove(change);
                 context.SaveChanges();
             }
             return(Json(new { success = true }));
         }
         catch (Exception ex)
         {
             return(GetJsonResult(ex));
         }
     }
 }
示例#7
0
        public JsonResult AddChange(ObservationChange model)
        {
            using (Entity context = new Entity())
            {
                try
                {
                    t_observation_change change = new t_observation_change();
                    change.observation_id   = model.ObservationId;
                    change.start_date       = model.StartDate;
                    change.description      = model.Description;
                    change.createdby_userid = CurrentUser.Id;
                    change.created_date     = DateTime.Now;
                    change.approved         = true; // all changes automatically approved
                    context.t_observation_change.Add(change);
                    context.SaveChanges();


                    context.Entry(change).Reference(n => n.createdby).Load();

                    return(Json(new
                    {
                        success = true,
                        ChangeId = change.observation_change_id,
                        ObservationId = change.observation_id,
                        StartDate = change.start_date.ToString("d"),
                        Description = change.description,
                        CreatedBy = change.createdby.full_name,
                        CreatedOn = change.created_date.ToString("d")
                    }));
                }
                catch (Exception ex)
                {
                    return(GetJsonResult(ex));
                }
            }
        }