コード例 #1
0
        public static ResponResultViewModel Is_Delete(MonitoringViewModel entity)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new MinProContext())
                {
                    t_monitoring mn = db.t_monitoring.Where(o => o.id == entity.id).FirstOrDefault();
                    if (mn != null)
                    {
                        mn.is_delete  = true;
                        mn.deleted_by = 1;
                        mn.deleted_on = DateTime.Now;
                        db.SaveChanges();
                        result.Entity = entity;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
コード例 #2
0
        public static ResponResultViewModel CreatePlacement(MonitoringViewModel entity)
        {
            //Untuk placement
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new MinProContext())

                {
                    t_monitoring mn = db.t_monitoring.Where(o => o.id == entity.id).FirstOrDefault();
                    if (mn != null)
                    {
                        mn.placement_date = entity.placement_date;
                        mn.placement_at   = entity.placement_at;
                        mn.notes          = entity.notes;

                        mn.modified_by = 2;
                        mn.modified_on = DateTime.Now;

                        db.SaveChanges();

                        result.Entity = entity;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
コード例 #3
0
        public static ResponResultViewModel Update(MonitoringViewModel entity)
        {
            //Untuk create dan edit
            ResponResultViewModel result = new ResponResultViewModel();

            try
            {
                using (var db = new MinProContext())
                {
                    //Create
                    if (entity.id == 0)
                    {
                        t_monitoring mn = new t_monitoring();
                        mn.biodata_id     = entity.biodata_id;
                        mn.idle_date      = entity.idle_date;
                        mn.last_project   = entity.last_project;
                        mn.idle_reason    = entity.idle_reason;
                        mn.placement_date = DateTime.Now;
                        mn.is_delete      = entity.is_delete;

                        mn.created_by = 1;
                        mn.created_on = DateTime.Now;


                        db.t_monitoring.Add(mn);
                        db.SaveChanges();

                        result.Entity = mn;
                    }
                    //Edit
                    else
                    {
                        t_monitoring mn = db.t_monitoring.Where(o => o.id == entity.id).FirstOrDefault();
                        if (mn != null)
                        {
                            mn.biodata_id   = entity.biodata_id;
                            mn.idle_date    = entity.idle_date;
                            mn.last_project = entity.last_project;
                            mn.idle_reason  = entity.idle_reason;
                            mn.is_delete    = entity.is_delete;

                            mn.modified_by = 2;
                            mn.modified_on = DateTime.Now;

                            db.SaveChanges();

                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success = false;
                            result.Message = "Idle not Found!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
コード例 #4
0
        public static ResponseResult Update(MonitoringViewModel entity)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XBC_Context())
                {
                    //CREATE
                    if (entity.id == 0)
                    {
                        t_monitoring mon = new t_monitoring();
                        mon.biodata_id   = entity.biodata_id;
                        mon.idle_date    = entity.idle_date;
                        mon.last_project = entity.last_project;
                        mon.idle_reason  = entity.idle_reason;
                        mon.is_delete    = entity.is_delete;

                        mon.created_by = entity.UserId;
                        mon.created_on = DateTime.Now;

                        db.t_monitoring.Add(mon);
                        db.SaveChanges();

                        object data = new
                        {
                            mon.id,
                            mon.biodata_id,
                            mon.idle_date,
                            mon.last_project,
                            mon.idle_reason
                        };
                        var json = new JavaScriptSerializer().Serialize(data);

                        t_audit_log log = new t_audit_log();
                        log.type        = "Insert";
                        log.json_insert = json;

                        log.created_by = entity.UserId;
                        log.created_on = DateTime.Now;

                        db.t_audit_log.Add(log);
                        db.SaveChanges();

                        entity.id     = mon.id;
                        result.Entity = entity;
                    }
                    else //EDIT
                    {
                        t_monitoring mon = db.t_monitoring
                                           .Where(o => o.id == entity.id)
                                           .FirstOrDefault();

                        if (mon != null)
                        {
                            object data = new
                            {
                                mon.id,
                                mon.biodata_id,
                                mon.idle_date,
                                mon.last_project,
                                mon.idle_reason
                            };
                            var         json = new JavaScriptSerializer().Serialize(data);
                            t_audit_log log  = new t_audit_log();
                            log.type        = "Modify";
                            log.json_before = json;

                            log.created_by = entity.UserId;
                            log.created_on = DateTime.Now;

                            mon.biodata_id   = entity.biodata_id;
                            mon.idle_date    = entity.idle_date;
                            mon.last_project = entity.last_project;
                            mon.idle_reason  = entity.idle_reason;

                            mon.modified_by = entity.UserId;
                            mon.modified_on = DateTime.Now;

                            object data2 = new
                            {
                                mon.id,
                                mon.biodata_id,
                                mon.idle_date,
                                mon.last_project,
                                mon.idle_reason,
                                mon.placement_at,
                                mon.placement_date,
                                mon.notes
                            };
                            var json2 = new JavaScriptSerializer().Serialize(data2);
                            log.json_after = json2;
                            db.t_audit_log.Add(log);

                            db.SaveChanges();

                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success      = false;
                            result.ErrorMessage = "Monitoring not found!";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
コード例 #5
0
        //PLACEMENT
        public static ResponseResult Placement(MonitoringViewModel entity)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XBC_Context())
                {
                    t_monitoring mon = db.t_monitoring
                                       .Where(o => o.id == entity.id)
                                       .FirstOrDefault();

                    if (mon != null)
                    {
                        object data = new
                        {
                            mon.id,
                            mon.biodata_id,
                            mon.idle_date,
                            mon.last_project,
                            mon.idle_reason
                        };
                        var         json = new JavaScriptSerializer().Serialize(data);
                        t_audit_log log  = new t_audit_log();
                        log.type        = "Modify";
                        log.json_before = json;

                        log.created_by = entity.UserId;
                        log.created_on = DateTime.Now;

                        mon.placement_date = entity.placement_date;
                        mon.placement_at   = entity.placement_at;
                        mon.notes          = entity.notes;

                        mon.modified_by = entity.UserId;
                        mon.modified_on = DateTime.Now;

                        object data2 = new
                        {
                            mon.id,
                            mon.biodata_id,
                            mon.idle_date,
                            mon.last_project,
                            mon.idle_reason,
                            mon.placement_at,
                            mon.placement_date,
                            mon.notes
                        };
                        var json2 = new JavaScriptSerializer().Serialize(data2);
                        log.json_after = json2;
                        db.t_audit_log.Add(log);

                        db.SaveChanges();
                        entity.name = mon.t_biodata.name; //untuk menampilkan name (t_biodata) di pesan success Placement (monitoring),
                        //karena monitoring tidak punya name
                        result.Entity = entity;
                    }
                    else
                    {
                        result.Success      = false;
                        result.ErrorMessage = "Monitoring not found!";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }