Beispiel #1
0
        public ActionResult Save(Documentary documentary)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new DocumentariesFormViewModel(documentary)
                {
                    Genres = _context.DocumentaryGenres.ToList()
                };
                return(View("DocumentariesForm", viewModel));
            }

            if (documentary.Id == 0)
            {
                documentary.DateAdded = DateTime.Now;
                _context.Documentaries.Add(documentary);
            }
            else
            {
                var documentaryInDb = _context.Documentaries.Single(d => d.Id == documentary.Id);
                documentaryInDb.Name               = documentary.Name;
                documentaryInDb.ReleaseDate        = documentary.ReleaseDate;
                documentaryInDb.NumberInStock      = documentary.NumberInStock;
                documentaryInDb.DocumentaryGenreId = documentary.DocumentaryGenreId;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Documentaries"));
        }
        public IHttpActionResult Get()
        {
            Documentary documentary   = CreateDocumentary();
            var         documentaries = documentary.GetDocumentaries();

            return(Ok(documentaries));
        }
Beispiel #3
0
        public ActionResult Delete()
        {
            try
            {
                int documentary_id = int.Parse(Request["documentary_id"]);
                using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
                {
                    Documentary doc = db.Documentaries.Find(documentary_id);
                    if (doc == null)
                    {
                        return(Json(new { success = false, message = "Mã quyết định không tồn tại" }));
                    }

                    if (doc.documentary_code != null)
                    {
                        return(Json(new { success = false, message = "Bạn không được xóa quyết định này" }));
                    }

                    db.Documentaries.Remove(doc);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Xóa thành công" }));
                }
            }
            catch (Exception)
            {
                return(Json(new { success = false, message = "Có lỗi xảy ra" }));
            }
        }
        public async Task <bool> AddDocumentary(Documentary documentary)
        {
            bool flag = true;

            try
            {
                DocumentaryModel documentaryModel = new DocumentaryModel();

                documentaryModel.DocumentaryId    = documentary.DocumentaryId;
                documentaryModel.DocumentaryName  = documentary.DocumentaryName;
                documentaryModel.DocumentaryGenre = documentary.DocumentaryGenre;
                documentaryModel.ActorId          = documentary.ActorId;

                //Create Actor object
                documentaryModel.Actor = _documentaryDbContext.Actors.Find(documentary.ActorId);

                if (documentaryModel.Actor == null)
                {
                    throw new InvalidActorIdException("Actor Doesn't Exist");
                }
                _documentaryDbContext.Documentaries.Add(documentaryModel);

                int rowAffected = await _documentaryDbContext.SaveChangesAsync();

                if (rowAffected < 1)
                {
                }
            }
            catch (InvalidSqlOperation)
            {
                throw new InvalidSqlOperation("Some Error Occurred");
            }

            return(flag);
        }
    public static void Main()
    {
        Console.WriteLine("\n\n***********************************\nOFFERTA  CONTENUTI  MEDIA\n");
        Console.WriteLine("");

        // Movie
        Console.WriteLine("___________________________________\n");
        Movie film = new Movie("Play it again, Sam", "Commedia", "Movie");

        film.Duration = 85;         // in minuti
        Console.WriteLine("- Contenuto   (i): " + "[" + film.Meta() + "] \n" + film.ToString());
        Console.WriteLine("___________________________________\n");

        // Documentary
        Console.WriteLine("___________________________________\n");
        Documentary doc = new Documentary("Inside Job", "Economics", "Documentary");

        doc.Duration = 108;         // in minuti
        Console.WriteLine("- Contenuto  (ii): " + "[" + doc.Meta() + "] \n" + doc.ToString());
        Console.WriteLine("___________________________________\n");

        // Serie Episode
        Console.WriteLine("___________________________________\n");
        SerieEpisode eps = new SerieEpisode("Amore", "Il Commissario Montalbano", 1, 12, "Serie Episode");

        eps.EpDuration = 110;         // in minuti
        Console.WriteLine("- Contenuto (iii): " + "[" + eps.Meta() + "] \n" + eps.ToString());
        Console.WriteLine("___________________________________\n");

        Console.WriteLine("\n\n***********************************\n\n");

        Console.WriteLine("Premere un qualsiasi tasto per interrompere l'esecuzione.");
        Console.ReadKey();
    }
Beispiel #6
0
        public ActionResult UpdateID(int documentary_id, string documentary_code)
        {
            QUANGHANHABCEntities DBContext = new QUANGHANHABCEntities();

            Documentary i = DBContext.Documentaries.Find(documentary_id);


            if (String.IsNullOrEmpty(documentary_code))
            {
                Response.Write("Vui lòng nhập mã quyết định!");
                return(new HttpStatusCodeResult(400));
            }
            else
            {
                try
                {
                    var query = (from x in DBContext.Documentaries
                                 where x.documentary_code == documentary_code
                                 select x).First();
                    Response.Write("Mã quyết định đã tồn tại!");
                    return(new HttpStatusCodeResult(400));
                }
                catch
                {
                    documentary_code   = documentary_code.Replace(" ", String.Empty);
                    i.documentary_code = documentary_code;
                    DBContext.SaveChanges();
                    return(new HttpStatusCodeResult(201));
                }
            }
        }
Beispiel #7
0
        public ActionResult Update(int documentary_id, string date_created, string person_created, string reason, string out_in_come)
        {
            QUANGHANHABCEntities DBContext = new QUANGHANHABCEntities();

            if (String.IsNullOrEmpty(date_created) || String.IsNullOrEmpty(person_created) || String.IsNullOrEmpty(out_in_come) || String.IsNullOrEmpty(reason))
            {
                Response.Write("Có lỗi xảy ra, xin vui lòng nhập lại");
                return(new HttpStatusCodeResult(400));
            }
            else
            {
                try
                {
                    Documentary documentary = DBContext.Documentaries.Where(a => a.documentary_id == documentary_id).First();
                    if (documentary != null)
                    {
                        documentary.date_created   = DateTime.Parse(date_created);
                        documentary.person_created = person_created;
                        documentary.reason         = reason;
                        documentary.out_in_come    = out_in_come;
                    }
                    DBContext.SaveChanges();
                    return(new HttpStatusCodeResult(201));
                }
                catch
                {
                    Response.Write("Có lỗi xảy ra, xin vui lòng nhập lại");
                    return(new HttpStatusCodeResult(400));
                }
            }
        }
 public DocumentariesFormViewModel(Documentary documentary)
 {
     Id                 = documentary.Id;
     Name               = documentary.Name;
     ReleaseDate        = documentary.ReleaseDate;
     NumberInStock      = documentary.NumberInStock;
     DocumentaryGenreId = documentary.DocumentaryGenreId;
 }
Beispiel #9
0
        public MetadataForm(string ticket, string fileId, string title = "")
        {
            InitializeComponent();

            this.Text = String.Format("{0} - Metadatos", title);

            _docType = null;
            _ticket  = ticket;
            _fileId  = fileId;
        }
Beispiel #10
0
 public ActionResult DeleteDoc(int docID)
 {
     using (QUANGHANHABCEntities db = new QUANGHANHABCEntities())
     {
         Documentary doc = db.Documentaries.Where(x => x.documentary_id == docID).FirstOrDefault <Documentary>();
         db.Documentaries.Remove(doc);
         db.SaveChanges();
         Response.Write("Xóa thành công!");
         return(new HttpStatusCodeResult(201));
     }
 }
Beispiel #11
0
        private void cbxDocumentaryTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            _docType = cbxDocumentaryTypes.SelectedItem as Documentary;

            metadataControl.ApplyChanges();

            if (_docType != null)
            {
                metadataControl.BindMetadata(_docType.elements);
            }
        }
        public ActionResult Update(string edit, int id)
        {
            if (edit != "")
            {
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        JArray list = JArray.Parse(edit);
                        foreach (JValue item in list)
                        {
                            if (item.Value.ToString() == "")
                            {
                                continue;
                            }

                            CameraRepairDetail temp = db.CameraRepairDetails.Where(x => x.documentary_id == id && x.room_id == item.Value.ToString()).FirstOrDefault();
                            if (temp.documentary_camera_repair_status == 0)
                            {
                                temp.documentary_camera_repair_status = 1;
                                Acceptance a = new Acceptance
                                {
                                    acceptance_date            = null,
                                    documentary_id             = id,
                                    room_id                    = item.Value.ToString(),
                                    acceptance_camera_quantity = temp.broken_camera_quantity
                                };
                                db.Acceptances.Add(a);
                            }
                        }
                        if ((from docu in db.Documentaries
                             join details in db.CameraRepairDetails on docu.documentary_id equals details.documentary_id
                             where docu.documentary_type == 8 && details.documentary_id == id && details.documentary_camera_repair_status == 0
                             select details).Count() == 0)
                        {
                            Documentary docu = db.Documentaries.Find(id);
                            docu.documentary_status = 2;
                        }

                        db.SaveChanges();
                        transaction.Commit();
                        return(Json(new { success = true, message = "Lưu thành công" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception e)
                    {
                        e.Message.ToString();
                        transaction.Rollback();
                        return(Json(new { success = false, message = "Có lỗi xảy ra" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            return(Json(new { success = true, message = "Lưu thành công" }, JsonRequestBehavior.AllowGet));
        }
 public async Task <IActionResult> AddDocumentary(Documentary documentary)
 {
     try
     {
         return(Ok(await _documentaryData.AddDocumentary(documentary)));
     }
     catch (InvalidActorIdException e)
     {
         return(BadRequest(e.Message));
     }
     catch (InvalidSqlOperation e)
     {
         return(BadRequest(e.Message));
     }
 }
        public ActionResult SetPost(Post model)
        {
            if (ModelState.IsValid)
            {
                var documentary = new Documentary {
                    Name = model.Name, Description = model.Description, Location = model.Location, Url = model.Url, UrlRedirect = model.UrlRedirect
                };
                db.Documentaries.Add(documentary);
                var result = db.SaveChanges();

                if (result == 1)
                {
                    return(RedirectToAction("Documentary", "Home"));
                }
            }
            return(View(model));
        }
Beispiel #15
0
 public ActionResult Index(int id)
 {
     try
     {
         QUANGHANHABCEntities DBContext   = new QUANGHANHABCEntities();
         Documentary          documentary = DBContext.Database.SqlQuery <Documentary>("SELECT docu.*, docu.[out/in_come] as out_in_come FROM Documentary_liquidation_details as detail inner join Documentary as docu on detail.documentary_id = docu.documentary_id WHERE docu.documentary_code IS NOT NULL AND detail.documentary_id = @documentary_id",
                                                                                      new SqlParameter("documentary_id", id)).First();
         ViewBag.id   = documentary.documentary_id;
         ViewBag.code = documentary.documentary_code as string;
         return(View("/Views/CDVT/Cap_nhat/Chitiet/Thanhly.cshtml"));
     }
     catch (Exception)
     {
         Response.Write("Số quyết định không tồn tại hoặc chưa được cấp");
         return(new HttpStatusCodeResult(400));
     }
 }
Beispiel #16
0
        //private readonly Guid _id;

        //public DocumentaryService(Guid id)
        //{
        //    _id = id;

        //}

        public bool CreateDocumentary(DocumentaryCreate model)
        {
            var entity =
                new Documentary()
            {
                Id             = _id,
                Title          = model.Title,
                Description    = model.Description,
                Genre          = model.Genre,
                MaturityRating = model.MaturityRating,
                RunTime        = model.RunTime,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Documentaries.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public async Task <List <Documentary> > ShowDocumentaries()
        {
            List <Documentary> documentaries = new List <Documentary>();

            try
            {
                List <DocumentaryModel> documentaryModels = await _documentaryDbContext.Documentaries.ToListAsync();

                //documentaries = new List<Documentary>();

                if (documentaryModels.Count == 0)
                {
                    throw new EmptyListException("No Documentaries Present");
                }

                foreach (var item in documentaryModels)
                {
                    Documentary documentary = new Documentary();

                    documentary.DocumentaryId    = item.DocumentaryId;
                    documentary.DocumentaryName  = item.DocumentaryName;
                    documentary.DocumentaryGenre = item.DocumentaryGenre;
                    documentary.ActorId          = item.ActorId;

                    documentary.actor = new Actor();
                    ActorModel actorModel = _documentaryDbContext.Actors.Find(item.ActorId);
                    documentary.actor.ActorId          = actorModel.ActorId;
                    documentary.actor.ActorName        = actorModel.ActorName;
                    documentary.actor.ActorGender      = actorModel.ActorGender;
                    documentary.actor.ActorDateOfBirth = actorModel.ActorDateOfBirth;
                    documentary.actor.ActorAge         = actorModel.ActorAge;

                    documentaries.Add(documentary);
                }
            }
            catch (InvalidSqlOperation)
            {
                throw new InvalidSqlOperation("Some error Occurred");
            }

            return(documentaries);
        }
        public ActionResult Index(int id)
        {
            try
            {
                db.Configuration.LazyLoadingEnabled = false;
                Documentary documentary = db.Documentaries.Find(id);

                if (documentary == null || String.IsNullOrEmpty(documentary.documentary_code))
                {
                    return(Redirect("/phong-cdvt/camera/xu-ly"));
                }

                List <Supply> supplies = db.Supplies.Select(x => new
                {
                    x.supply_id,
                    x.supply_name
                }).ToList().Select(x => new Supply
                {
                    supply_id   = x.supply_id,
                    supply_name = x.supply_name
                }).ToList();
                ViewBag.Supplies = supplies;

                if (documentary.documentary_status == 1)
                {
                    ViewBag.AddAble = true;
                }
                else
                {
                    ViewBag.AddAble = false;
                }
                ViewBag.id   = documentary.documentary_id;
                ViewBag.code = documentary.documentary_code as string;
                return(View("/Views/Camera/Quyetdinh/SuaChua/XuLy.cshtml"));
            }
            catch (Exception e)
            {
                e.Message.ToString();
                Response.Write("Số quyết định không tồn tại hoặc chưa được cấp");
                return(new HttpStatusCodeResult(400));
            }
        }
        public ActionResult Edit(string room_id, int documentary_id)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Acceptance acceptance = db.Acceptances.Where(x => x.documentary_id == documentary_id && x.room_id == room_id).FirstOrDefault();
                    if (acceptance != null && acceptance.acceptance_date != null)
                    {
                        return(Json(new { success = false, message = "Thiết bị đã được nghiệm thu" }));
                    }

                    acceptance.acceptance_date = DateTime.Now;
                    db.SaveChanges();

                    int acceptance_left = db.Acceptances.Where(x => x.documentary_id == documentary_id && x.acceptance_date != null).Count();

                    if (acceptance_left == 0)
                    {
                        Documentary documentary = db.Documentaries.Find(documentary_id);
                        documentary.documentary_status = 3;
                    }

                    Room r = db.Rooms.Find(room_id);
                    CameraRepairDetail detail = db.CameraRepairDetails.Where(x => x.documentary_id == documentary_id && x.room_id == room_id).FirstOrDefault();
                    r.camera_available += detail.broken_camera_quantity;

                    db.SaveChanges();
                    transaction.Commit();
                    return(Json(new { success = true, message = "Nghiệm thu thành công" }));
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                    transaction.Rollback();
                    return(Json(new { success = false, message = "Nghiệm thu thất bại" }));
                }
            }
        }
        public ActionResult editpost(string edit, string id)
        {
            ViewBag.id = id as string;
            if (edit != "")
            {
                QUANGHANHABCEntities DBContext = new QUANGHANHABCEntities();
                using (DbContextTransaction transaction = DBContext.Database.BeginTransaction())
                {
                    try
                    {
                        int idnumber = int.Parse(id);
                        edit = edit.Substring(0, edit.Length - 1);
                        char[]   spearator = { '^' };
                        String[] list      = edit.Split(spearator,
                                                        StringSplitOptions.RemoveEmptyEntries);
                        foreach (var item in list)
                        {
                            Documentary_maintain_details temp = DBContext.Documentary_maintain_details.Find(idnumber, item);
                            temp.equipment_maintain_status = 1;
                            DBContext.SaveChanges();
                        }
                        if (DBContext.Database.SqlQuery <Documentary_maintain_detailsDB>("select details.equipment_maintain_status from Department depa inner join Documentary docu on depa.department_id = docu.department_id inner join Documentary_maintain_details details on details.documentary_id = docu.documentary_id inner join Equipment e on e.equipmentId = details.equipmentId where docu.documentary_type = 2 and details.documentary_id = @documentary_id and equipment_maintain_status = '0'", new SqlParameter("documentary_id", id)).Count() == 0)
                        {
                            Documentary docu = DBContext.Documentaries.Find(idnumber);
                            docu.documentary_status = 2;
                        }

                        DBContext.SaveChanges();
                        transaction.Commit();
                        return(new HttpStatusCodeResult(201));
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        Response.Write("Có lỗi xảy ra, xin vui lòng nhập lại");
                        return(new HttpStatusCodeResult(400));
                    }
                }
            }
            return(new HttpStatusCodeResult(201));
        }
Beispiel #21
0
        public static PlayList LoadPlayListFromFile(string filePath)
        {
            PlayList     pl = new PlayList();
            StreamReader sr = new StreamReader(filePath);

            while (sr.Peek() >= 0)
            {
                string    Entry      = sr.ReadLine();
                string [] EntryField = Entry.Split('#');

                if (EntryField[0] == "D")
                {
                    int         duration = Convert.ToInt32(EntryField[2]);
                    Documentary doc      = new Documentary(EntryField[1], duration / 60, new ArtWork(EntryField[1]), EntryField[3]);
                    IPlayable   toadd    = (IPlayable)doc;
                    pl.Add(toadd);
                }
                else if (EntryField[0] == "M")
                {
                    int       duration = Convert.ToInt32(EntryField[2]);
                    Movie     film     = new Movie(EntryField[1], duration / 60, new ArtWork(EntryField[1]), EntryField[3]);
                    IPlayable toadd    = (IPlayable)film;
                    pl.Add(toadd);
                }
                else if (EntryField[0] == "S")
                {
                    int          duration = Convert.ToInt32(EntryField[2]);
                    int          season   = Convert.ToInt32(EntryField[4]);
                    int          episode  = Convert.ToInt32(EntryField[5]);
                    SerieEpisode serie    = new SerieEpisode(EntryField[1], duration / 60, new ArtWork(EntryField[1]), EntryField[3], season, episode);
                    IPlayable    toadd    = (IPlayable)serie;
                    pl.Add(toadd);
                }
            }

            return(pl);
        }
Beispiel #22
0
    static void Main()
    {
        // Print the list of the available contents
        Console.WriteLine("Contents:\n\n");

        Movie film = new Movie("Play it again, Sam", 85, new ArtWork("play_it_again_Sam"), "Comedy");

        Console.WriteLine("Content: {0}, Time: {1}, Genre: {2}", film.title, film.Duration(), film.genre);

        Documentary doc = new Documentary("Inside Job", 108, new ArtWork("inside_job"), "Economics");

        Console.WriteLine("Content: {0}, Time: {1}, Topic: {2}", doc.title, doc.Duration(), doc.topic);

        SerieEpisode serieep = new SerieEpisode("Amore", 120, new ArtWork("comm_Montalbano_S12E1"), "Il Commissario Montalbano", 12, 1);

        Console.WriteLine("Content: {0}, Time: {1}, Serie: {2}, Season: {3}, Episode Number: {4}", serieep.title, serieep.Duration(), serieep.serie, serieep.season, serieep.epNumber);


        // assume we choose to watch at this awesome Woody Allen masterpiece
        // details of the contents are reported by invoking proper methods
        Console.WriteLine("\n\nContent analysed: " + film.metalabel + ". Title: " + film.GetTitle());
        Console.WriteLine("Content duration (mins): {0}", film.GetDurationMins());

        IImage art = (IImage)film.GetArtWork();

        Console.WriteLine("ArtWork Details: File Path: {0}, Thumbnail Height and Width respectively (pixels) : {1}; {2}", art.GetPath(), art.GetHeight(), art.GetWidth());


        // content is to be actioned upon by playing, pausing, stopping it.
        // details about time elapsed are also shown.

        film.Stop();
        film.Pause();

        film.Play();

        ContentPlayForAWhile();

        film.Pause();

        ContentPlayForAWhile();

        film.Play();

        ContentPlayForAWhile();

        film.Play();

        ContentPlayForAWhile();

        film.Stop();

        ContentPlayForAWhile();

        film.Stop();

        ContentPlayForAWhile();

        film.Play();

        ContentPlayForAWhile(); ContentPlayForAWhile();

        film.Pause();

        ContentPlayForAWhile();

        film.Pause();

        Console.WriteLine("\n\nPress any Key to quit.");
        Console.ReadKey();
    }
 //Add New Documentary
 public async Task <bool> AddDocumentary(Documentary documentary)
 {
     return(await _documentaryData.AddDocumentary(documentary));
 }
Beispiel #24
0
        public ActionResult Update()
        {
            int    documentary_id   = int.Parse(Request["documentary_id"]);
            string documentary_code = Request["documentary_code"];
            string reason           = Request["reason"];
            string out_in_come      = Request["out_in_come"];

            using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
            {
                using (DbContextTransaction trans = db.Database.BeginTransaction())
                {
                    try
                    {
                        if (db.Documentaries.Where(x => x.documentary_code == documentary_code).FirstOrDefault() != null)
                        {
                            return(Json(new { success = false, message = "Số quyết định đã tồn tại" }));
                        }
                        Documentary doc = db.Documentaries.Find(documentary_id);
                        if (doc == null)
                        {
                            return(Json(new { success = false, message = "Quyết định không tồn tại" }));
                        }
                        doc.documentary_code = documentary_code == "" ? null : documentary_code;
                        doc.reason           = reason;
                        doc.out_income       = out_in_come;

                        if (doc.documentary_code != null)
                        {
                            Notification noti = new Notification
                            {
                                description = ""
                            };
                            switch (doc.documentary_type)
                            {
                            case 1:
                                (from a in db.Equipments
                                 join b in db.RepairDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 3);

                                noti.description = "sua chua";
                                break;

                            case 2:
                                (from a in db.Equipments
                                 join b in db.MaintainDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 5);

                                noti.description = "bao duong";
                                break;

                            case 3:
                                (from a in db.Equipments
                                 join b in db.MovelineDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 6);

                                noti.description = "dieu dong";
                                break;

                            case 4:
                                (from a in db.Equipments
                                 join b in db.RevokeDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 7);

                                noti.description = "thu hoi";
                                break;

                            case 5:
                                (from a in db.Equipments
                                 join b in db.LiquidationDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 8);

                                noti.description = "thanh ly";
                                break;

                            case 6:
                                (from a in db.Equipments
                                 join b in db.BigMaintainDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 9);

                                noti.description = "trung dai tu";
                                break;

                            case 7:
                                (from a in db.Equipments
                                 join b in db.ImproveDetails on a.equipment_id equals b.equipment_id
                                 where b.documentary_id == documentary_id
                                 select a).ToList().ForEach(x => x.current_status = 16);

                                noti.description = "cai tien";
                                break;

                            case 8:
                                break;

                            default:
                                return(Json(new { success = false, message = "Loại quyết định không tồn tại" }));
                            }
                            if (!noti.description.Equals(""))
                            {
                                noti.date          = DateTime.Now.Date;
                                noti.department_id = doc.department_id_to;
                                noti.id_problem    = doc.documentary_id;
                                noti.isread        = false;
                                db.Notifications.Add(noti);
                                db.SaveChanges();
                            }
                        }

                        db.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.Rollback();
                        return(Json(new { success = false, message = "Có lỗi xảy ra" }));
                    }
                }
            }
            return(Json(new { success = true, message = "Cập nhật thành công" }));
        }
        public ActionResult Add(string out_in_come, string data, string department_id, string reason)
        {
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = DBContext.Database.BeginTransaction())
            {
                try
                {
                    Department department = DBContext.Departments.Find(department_id);
                    if (department == null)
                    {
                        return(Json(new { success = false, message = "Phòng ban không tồn tại" }));
                    }

                    Documentary documentary = new Documentary
                    {
                        documentary_type = 8,
                        date_created     = DateTime.Now,
                        person_created   = Session["Name"] + ""
                    };
                    documentary.reason             = reason;
                    documentary.out_income         = out_in_come;
                    documentary.department_id_to   = department_id;
                    documentary.documentary_status = 1;
                    DBContext.Documentaries.Add(documentary);
                    DBContext.SaveChanges();
                    JArray json = JArray.Parse(data);
                    foreach (JObject item in json)
                    {
                        string room_id            = item["id"].ToString();
                        string repair_requirement = item["repair_requirement"].ToString();

                        CameraRepairDetail drd = new CameraRepairDetail
                        {
                            documentary_camera_repair_status = 0,
                            documentary_id         = documentary.documentary_id,
                            room_id                = room_id,
                            broken_camera_quantity = (int)item["broken_camera_quantity"],
                            repair_requirement     = repair_requirement,
                            note          = (string)item["note"],
                            department_id = (string)item["department_id"]
                        };
                        DBContext.CameraRepairDetails.Add(drd);

                        JArray vattu = (JArray)item.SelectToken("vattu");
                        foreach (JObject jObject in vattu)
                        {
                            string       supply_id = (string)jObject["supply_id"];
                            int          quantity  = (int)jObject["quantity"];
                            RepairCamera sde       = new RepairCamera
                            {
                                documentary_id = documentary.documentary_id,
                                room_id        = room_id,
                                supply_id      = supply_id,
                                quantity_plan  = quantity
                            };
                            DBContext.RepairCameras.Add(sde);
                        }
                    }
                    DBContext.SaveChanges();
                    transaction.Commit();
                    return(Json(new { success = true }));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(Json(new { success = false, message = "Có lỗi xảy ra" }));
                }
            }
        }
        public ActionResult Add(string out_in_come, string data, string department_id_to, string reason)
        {
            JArray json = JArray.Parse(data);
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = DBContext.Database.BeginTransaction())
            {
                try
                {
                    Documentary documentary = new Documentary
                    {
                        documentary_type   = 1,
                        department_id_to   = department_id_to,
                        date_created       = DateTime.Now,
                        person_created     = Session["Name"] + "",
                        reason             = reason,
                        out_income         = out_in_come,
                        documentary_status = 1
                    };
                    DBContext.Documentaries.Add(documentary);
                    DBContext.SaveChanges();

                    // Vị trí của thiết bị con được lấy theo vị trí của thiết bị to
                    List <string> list = new List <string>();
                    foreach (JObject item in json)
                    {
                        list.Add(item["attachTo"].Type == JTokenType.Null ? item["equipmentId"].ToString() : item["attachTo"].ToString());
                    }

                    var dict = (from e in DBContext.Equipments
                                join d in DBContext.Departments on e.department_id equals d.department_id
                                where list.Contains(e.equipment_id)
                                select new
                    {
                        e.equipment_id,
                        d.department_id
                    })
                               .Select(x => new { x.equipment_id, x.department_id })
                               .AsEnumerable()
                               .ToDictionary(d => d.equipment_id, d => d.department_id);

                    foreach (JObject item in json)
                    {
                        DateTime finish_date_plan = DateTime.ParseExact((string)item["date"], "dd/MM/yyyy", null);
                        string   equipmentId      = item["equipmentId"].ToString();
                        string   attach_to        = item["attachTo"].Type == JTokenType.Null ? null : item["attachTo"].ToString();

                        RepairDetail drd = new RepairDetail
                        {
                            department_id_from      = attach_to == null ? dict[equipmentId] : dict[attach_to],
                            equipment_repair_status = 0,
                            repair_type             = item["type"].ToString(),
                            repair_reason           = item["reason"].ToString(),
                            finish_date_plan        = finish_date_plan,
                            documentary_id          = documentary.documentary_id,
                            equipment_id            = equipmentId,
                            attach_to  = attach_to,
                            is_visible = true,
                            quantity   = int.Parse(item["quantity"].ToString())
                        };
                        DBContext.RepairDetails.Add(drd);
                        DBContext.SaveChanges();
                        bool used = false;

                        JObject vattu = (JObject)item["supply"];
                        if (vattu != null)
                        {
                            foreach (var jObject in vattu)
                            {
                                RepairEquipment sde = new RepairEquipment
                                {
                                    documentary_repair_id = drd.documentary_repair_id,
                                    supply_id             = jObject.Key,
                                    quantity_plan         = int.Parse(jObject.Value.ToString()),
                                };
                                used = true;
                                DBContext.RepairEquipments.Add(sde);
                            }
                            DBContext.SaveChanges();
                        }

                        JObject thietbi = (JObject)item["equipment"];
                        if (thietbi != null)
                        {
                            foreach (var jObject in thietbi)
                            {
                                RepairEquipment sde = new RepairEquipment
                                {
                                    documentary_repair_id = drd.documentary_repair_id,
                                    equipment_id          = jObject.Key,
                                    quantity_plan         = int.Parse(jObject.Value.ToString()),
                                };
                                used = true;
                                DBContext.RepairEquipments.Add(sde);
                            }
                            DBContext.SaveChanges();
                        }

                        if (!used)
                        {
                            transaction.Rollback();
                            string message = "Thiết bị " + (attach_to == null ? (equipmentId + " chưa được chọn thiết bị con hoặc vật tư") : (attach_to + $" ({equipmentId}) chưa được chọn vật tư"));
                            return(Json(new { success = false, message = "Thiết bị chưa được chọn" }));
                        }
                    }

                    transaction.Commit();
                    return(Json(new { success = true }));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(Json(new { success = false, message = "Có lỗi xảy ra" }));
                }
            }
        }
        public ActionResult Index()
        {
            int id = int.Parse(Request["id"]);

            using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
            {
                db.Configuration.LazyLoadingEnabled = false;

                Documentary documentary = db.Documentaries.Find(id);
                if (documentary == null)
                {
                    return(Redirect("/phong-cdvt/camera/quyet-dinh/sua-chua"));
                }

                ViewBag.documentary_code = documentary.documentary_code;

                var listRooms = (from r in db.Rooms
                                 join d in db.CameraRepairDetails on r.room_id equals d.room_id
                                 join depa in db.Departments on r.department_id equals depa.department_id
                                 where d.documentary_id == id
                                 select new RoomDetail
                {
                    room_id = r.room_id,
                    room_name = r.room_name,
                    department_name = depa.department_name,
                    broken_camera_quantity = d.broken_camera_quantity,
                    repair_requirement = d.repair_requirement,
                    note = d.note
                }).ToList();
                ViewBag.listRooms = listRooms;

                var listSupplies = (from r in db.RepairCameras
                                    join s in db.Supplies on r.supply_id equals s.supply_id
                                    select new
                {
                    r.room_id,
                    r.supply_id,
                    r.quantity_plan,
                    s.supply_name
                }).ToList();

                JObject temp = new JObject();
                foreach (var room in listRooms)
                {
                    JArray list = new JArray();
                    for (int i = 0; i < listSupplies.Count; i++)
                    {
                        var supply = listSupplies[i];
                        if (supply.room_id.Equals(room.room_id))
                        {
                            list.Add(JToken.FromObject(new
                            {
                                supply.supply_id,
                                supply.supply_name,
                                supply.quantity_plan
                            }));
                        }
                    }
                    temp.Add(room.room_id.ToString(), list);
                }
                ViewBag.listSupplies = temp.ToString();
            }
            return(View("/Views/Camera/Quyetdinh/SuaChua/ChiTiet.cshtml"));
        }