Example #1
0
        public static ResponResultViewModel Deact(BatchViewModel model)
        {
            ResponResultViewModel result = new ResponResultViewModel();

            using (var db = new MinProContext())
            {
                t_batch batch = db.t_batch.Where(x => x.id == model.id).FirstOrDefault();
                batch.is_delete  = false;
                batch.deleted_by = 1;
                batch.deleted_on = DateTime.Now;
                batch.name       = model.name;

                try
                {
                    db.SaveChanges();
                    result.Entity = model;
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.Message = e.Message;
                }
            }
            return(result);
        }
Example #2
0
        // Update (Edit & Create)
        public static ResponseResult Update(BatchViewModel entity)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XBC_Context())
                {
                    if (entity.id == 0) // Create
                    {
                        t_batch bt = new t_batch();
                        bt.name             = entity.name;
                        bt.technology_id    = entity.technologyId;
                        bt.period_to        = entity.periodTo;
                        bt.bootcamp_type_id = entity.bootcampTypeId;
                        bt.room_id          = entity.roomId;
                        bt.trainer_id       = entity.trainerId;
                        bt.period_from      = entity.periodFrom;
                        bt.notes            = entity.notes;

                        bt.created_by = entity.UserId;
                        bt.created_on = DateTime.Now;
                        bt.is_delete  = false;
                        db.t_batch.Add(bt);
                        db.SaveChanges();

                        // Audit Log Insert
                        var         json = new JavaScriptSerializer().Serialize(bt);
                        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     = bt.id;
                        result.Entity = entity;
                    }
                    else // Edit
                    {
                        t_batch bt = db.t_batch.Where(o => o.id == entity.id).FirstOrDefault();
                        if (bt != null)
                        {
                            var    Serial     = new JavaScriptSerializer();
                            object dataBefore = new //Mengambil Data Before for Log
                            {
                                bt.name,
                                bt.technology_id,
                                bt.period_to,
                                bt.bootcamp_type_id,
                                bt.room_id,
                                bt.trainer_id,
                                bt.period_from,
                                bt.notes
                            };

                            bt.name             = entity.name;
                            bt.technology_id    = entity.technologyId;
                            bt.period_to        = entity.periodTo;
                            bt.bootcamp_type_id = entity.bootcampTypeId;
                            bt.room_id          = entity.roomId;
                            bt.trainer_id       = entity.trainerId;
                            bt.period_from      = entity.periodFrom;
                            bt.notes            = entity.notes;

                            bt.modified_by = entity.UserId;
                            bt.modified_on = DateTime.Now;
                            db.SaveChanges();

                            // Audit Log Modify
                            object dataAfter = new
                            {
                                bt.name,
                                bt.technology_id,
                                bt.period_to,
                                bt.bootcamp_type_id,
                                bt.room_id,
                                bt.trainer_id,
                                bt.period_from,
                                bt.notes
                            };

                            t_audit_log log = new t_audit_log();
                            log.type        = "MODIFY";
                            log.json_before = Serial.Serialize(dataBefore);
                            log.json_after  = Serial.Serialize(dataAfter);
                            log.created_by  = entity.UserId;
                            log.created_on  = DateTime.Now;
                            db.t_audit_log.Add(log);
                            db.SaveChanges();

                            result.Entity = entity;
                        }
                        else
                        {
                            result.Success      = false;
                            result.ErrorMessage = "Betch Not Found";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Example #3
0
        public static ResponResultViewModel Update(BatchViewModel entity)
        {
            //untuk create & edit
            ResponResultViewModel result = new ResponResultViewModel();

            if (entity.period_from != null && entity.period_to != null && entity.room_id != 0 && entity.bootcamp_type_id != 0)
            {
                try
                {
                    using (var db = new MinProContext())
                    {
                        if (entity.id == 0)
                        {
                            t_batch batch = new t_batch();
                            batch.technology_id    = entity.technology_id;
                            batch.name             = entity.name;
                            batch.trainer_id       = entity.trainer_id;
                            batch.period_from      = entity.period_from;
                            batch.period_to        = entity.period_to;
                            batch.room_id          = entity.room_id;
                            batch.bootcamp_type_id = entity.bootcamp_type_id;
                            batch.notes            = entity.notes;
                            batch.is_delete        = entity.is_delete;

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

                            db.t_batch.Add(batch);
                            db.SaveChanges();

                            result.Entity = batch;
                        }
                        else
                        {
                            t_batch batch = db.t_batch.Where(x => x.id == entity.id).FirstOrDefault();
                            if (batch != null)
                            {
                                batch.technology_id    = entity.technology_id;
                                batch.name             = entity.name;
                                batch.trainer_id       = entity.trainer_id;
                                batch.period_from      = entity.period_from;
                                batch.period_to        = entity.period_to;
                                batch.room_id          = entity.room_id;
                                batch.bootcamp_type_id = entity.bootcamp_type_id;
                                batch.notes            = entity.notes;
                                batch.is_delete        = entity.is_delete;

                                batch.modified_by = 1;
                                batch.modified_on = DateTime.Now;

                                db.SaveChanges();
                                result.Entity = entity;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.Message = e.Message;
                }
            }
            else
            {
                result.Success = false;
                result.Message = "Can't save data!";
            }
            return(result);
        }