コード例 #1
0
        public ActionResult Edit(CONTRACTE contracte, FormCollection formCollection, string[] selectedServices)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contracte).State = EntityState.Modified;
                db.SaveChanges();
                //updateCoursesService(selectedServices, contracte);

                var oldServ = from ss in db.SERVICII_CONTRACT
                              where ss.SC_C_ID == contracte.C_ID
                              select ss;
                foreach (var ss in oldServ)
                {
                    SERVICII_CONTRACT cc = db.SERVICII_CONTRACT.Find(ss.SC_ID);
                    db.SERVICII_CONTRACT.Remove(cc);
                }
                foreach (string s in selectedServices)
                {
                    SERVICII_CONTRACT cntr = new SERVICII_CONTRACT();
                    cntr.SC_C_ID = contracte.C_ID;
                    cntr.SC_S_ID = Convert.ToInt32(s);
                    db.SERVICII_CONTRACT.Add(cntr);
                }
                //if (db.Entry(contracte).State == EntityState.Modified)
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.C_PERSOANA_ID = new SelectList(db.PERSOANE, "P_ID", "P_NUME", contracte.C_PERSOANA_ID);
            //ViewBag.C_MONEDA = new SelectList(idType, "L_ID", "L_NUME", contracte.C_MONEDA);
            return(View(contracte));
        }
コード例 #2
0
        private void updateCoursesService(string[] selectedServices, CONTRACTE contracte)
        {
            var servType = from lib in db.LIBRARIE
                           where lib.L_TIP == "SERVICIU"
                           select lib;
            var selectedServicesHS = new HashSet <string>(selectedServices);

            foreach (var s in servType)
            {
                SERVICII_CONTRACT cntr = new SERVICII_CONTRACT();
                cntr.SC_C_ID = contracte.C_ID;
                cntr.SC_S_ID = Convert.ToInt32(s.L_ID);

                if (selectedServicesHS.Contains(s.L_ID.ToString()))
                {
                    db.SERVICII_CONTRACT.Add(cntr);
                }
                else
                {
                    //var idSel = from ids in db.SERVICII_CONTRACT
                    //            where ids.SC_C_ID == contracte.C_ID && ids.SC_S_ID == Convert.ToInt32(s.L_ID)
                    //            select ids.SC_ID;
                    db.SERVICII_CONTRACT.Remove(cntr);
                }
            }
            db.SaveChanges();
        }
コード例 #3
0
        public ActionResult Create(CONTRACTE contracte, FormCollection formCollection, string[] selectedServices)
        {
            if (ModelState.IsValid)
            {
                db.CONTRACTE.Add(contracte);
                db.SaveChanges();
                if (selectedServices != null)
                {
                    foreach (string s in selectedServices)
                    {
                        SERVICII_CONTRACT cntr = new SERVICII_CONTRACT();
                        cntr.SC_C_ID = contracte.C_ID;
                        cntr.SC_S_ID = Convert.ToInt32(s);
                        db.SERVICII_CONTRACT.Add(cntr);
                    }
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.C_PERSOANA_ID = new SelectList(db.PERSOANE, "P_ID", "P_NUME", contracte.C_PERSOANA_ID);
            var servType = from lib in db.LIBRARIE
                           where lib.L_TIP == "SERVICIU"
                           select lib;

            ViewBag.ListaServicii = servType.ToList();
            var idType = from lib in db.LIBRARIE
                         where lib.L_TIP == "MONEDA"
                         select lib;

            ViewBag.C_MONEDA = new SelectList(idType, "L_ID", "L_NUME", contracte.C_MONEDA);
            return(View(contracte));
        }
コード例 #4
0
        //
        // GET: /Contracts/Create

        public ActionResult Create()
        {
            var servType = from lib in db.LIBRARIE
                           where lib.L_TIP == "SERVICIU"
                           select lib;

            ViewBag.ListaServicii = servType.ToList();
            var idType = from lib in db.LIBRARIE
                         where lib.L_TIP == "MONEDA"
                         select lib;

            ViewBag.C_MONEDA = new SelectList(idType, "L_ID", "L_NUME");
            //var contractServ = from cs in db.SERVICII_CONTRACT
            //                   select new SERVICII_CONTRACT { SC_ID = cs.SC_ID, SC_C_ID = cs.SC_C_ID, SC_S_ID = cs.SC_S_ID, CONTRACTE = cs.CONTRACTE, LIBRARIE = cs.LIBRARIE };

            //CONTRACTE contract = db.CONTRACTEs
            //        .Include(c => c.LIBRARIE);
            CONTRACTE cntr = new CONTRACTE();

            cntr.C_DATA       = DateTime.Now;
            cntr.C_AVANS_DATA = DateTime.Now;
            if (db.CONTRACTE.Count() == 0)
            {
                cntr.C_NUMAR = 1;
            }
            else
            {
                cntr.C_NUMAR = db.CONTRACTE.Max(c => c.C_NUMAR) + 1;
            }
            return(View(cntr));
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            CONTRACTE contracte = db.CONTRACTE.Find(id);

            db.CONTRACTE.Remove(contracte);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public IHttpActionResult PutCONTRACTE(int id, CONTRACTE cONTRACTE)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cONTRACTE.C_ID)
            {
                return(BadRequest());
            }

            var oldSerList = db.SERVICII_CONTRACT.Where(w => w.SC_C_ID == id).Select(s => s.SC_S_ID).ToArray();;
            var newSerList = cONTRACTE.SERVICII_CONTRACT.Select(s => s.SC_S_ID).ToArray();

            var toAdd = newSerList.Except(oldSerList);
            //var toDelete = oldSerList.Except(newSerList).Select(s=>s.SC_S_ID).ToArray();
            var toDelete = oldSerList.Except(newSerList);

            cONTRACTE.PERSOANE          = null;
            cONTRACTE.LIBRARIE          = null;
            cONTRACTE.SERVICII_CONTRACT = null;
            db.Entry(cONTRACTE).State   = EntityState.Modified;

            try
            {
                //add new services
                var addService = new SERVICII_CONTRACT();
                foreach (var sc in toAdd)
                {
                    addService         = new SERVICII_CONTRACT();
                    addService.SC_C_ID = id;
                    addService.SC_S_ID = sc;
                    db.SERVICII_CONTRACT.Add(addService);
                }

                //delete services
                foreach (var scd in toDelete)
                {
                    db.SERVICII_CONTRACT.Remove(db.SERVICII_CONTRACT.Where(w => w.SC_S_ID == scd && w.SC_C_ID == id).FirstOrDefault());
                }
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CONTRACTEExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #7
0
        //
        // GET: /Contracts/Delete/5

        public ActionResult Delete(int id = 0)
        {
            CONTRACTE contracte = db.CONTRACTE.Find(id);

            if (contracte == null)
            {
                return(HttpNotFound());
            }
            return(View(contracte));
        }
コード例 #8
0
        public IHttpActionResult GetCONTRACTE(int id)
        {
            CONTRACTE cONTRACTE = db.CONTRACTEs.Find(id);

            if (cONTRACTE == null)
            {
                return(NotFound());
            }

            return(Ok(cONTRACTE));
        }
コード例 #9
0
        public IHttpActionResult DeleteCONTRACTE(int id)
        {
            CONTRACTE cONTRACTE = db.CONTRACTEs.Find(id);

            if (cONTRACTE == null)
            {
                return(NotFound());
            }

            db.CONTRACTEs.Remove(cONTRACTE);
            db.SaveChanges();

            return(Ok(cONTRACTE));
        }
コード例 #10
0
        //
        // GET: /Contracts/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CONTRACTE contracte = db.CONTRACTE.Find(id);

            if (contracte == null)
            {
                return(HttpNotFound());
            }
            ViewBag.C_PERSOANA_ID = new SelectList(db.PERSOANE, "P_ID", "P_NUME", contracte.C_PERSOANA_ID);
            var idType = from lib in db.LIBRARIE
                         where lib.L_TIP == "MONEDA"
                         select lib;

            ViewBag.C_MONEDA = new SelectList(idType, "L_ID", "L_NUME", contracte.C_MONEDA);

            //SERVICII_CONTRACT cntr = db.SERVICII_CONTRACT
            //    .Include(i => i.LIBRARIE)
            //    .Where(i => i.SC_C_ID == id)
            //    .Single();
            PopulateAssignedCourseData(id);
            return(View(contracte));
        }
コード例 #11
0
        public IHttpActionResult PostCONTRACTE(CONTRACTE cONTRACTE)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            try
            {
                //Contracte
                db.CONTRACTEs.Add(cONTRACTE);

                //Servicii
                foreach (var sc in cONTRACTE.SERVICII_CONTRACT)
                {
                    db.SERVICII_CONTRACT.Add(sc);
                }
                db.SaveChanges();

                return(CreatedAtRoute("DefaultApi", new { id = cONTRACTE.C_ID }, cONTRACTE));
            }
            catch (Exception ex)
            { throw ex; }
        }
コード例 #12
0
        //
        // GET: /Contracts/Details/5

        public ActionResult Details(int id = 0)
        {
            CONTRACTE contracte = db.CONTRACTE.Find(id);

            string     cale   = Request.PhysicalApplicationPath + @"Temp\" + id + ".pdf";
            PdfReader  reader = new PdfReader(Request.PhysicalApplicationPath + @"Temp\Contract.pdf");
            PdfStamper stamp1 = new PdfStamper(reader, new FileStream(cale, FileMode.Create));
            AcroFields form1  = stamp1.AcroFields;

            var cntr          = (db.CONTRACTE.Include(c => c.PERSOANE).Include(c => c.PERSOANE.LIBRARIE).Where(c => c.C_ID == id)).ToList();
            var listaServicii = from ls in db.SERVICII_CONTRACT.Include(s => s.LIBRARIE)
                                where ls.SC_C_ID == id
                                select ls.LIBRARIE.L_NUME;
            string pdfS = string.Empty;

            if (listaServicii.Count() > 0)
            {
                foreach (var s in listaServicii)
                {
                    pdfS += s.ToString() + ",";
                }
                pdfS = pdfS.Remove(pdfS.Length - 1);
            }

            var row = cntr[0];

            try {
                form1.SetField("Nr", row.C_NUMAR.ToString());
                form1.SetField("DataZi", row.C_DATA.Day.ToString());
                form1.SetField("DataLuna", row.C_DATA.Month.ToString());
                form1.SetField("Nume", row.PERSOANE.P_NUME);
                form1.SetField("Prenume", row.PERSOANE.P_PRENUME);
                form1.SetField("CNP", row.PERSOANE.P_CNP);
                form1.SetField("CI", row.PERSOANE.LIBRARIE.L_NUME + " " + row.PERSOANE.P_ID_VALUE);
                form1.SetField("DataNasterii", row.PERSOANE.P_DATA_NASTERII.HasValue ? Convert.ToDateTime(row.PERSOANE.P_DATA_NASTERII).ToString("dd/MMM/yyyy") : "");
                form1.SetField("Adresa", row.PERSOANE.P_ADRESA + " " + row.PERSOANE.P_ORAS + " " + row.PERSOANE.P_JUDET);
                form1.SetField("Telefon", row.PERSOANE.P_TEL);
                form1.SetField("Servicii", pdfS + " " +
                               (!string.IsNullOrEmpty(row.C_TARA) ? row.C_TARA : "") + " " +
                               (!string.IsNullOrEmpty(row.C_ORAS) ? row.C_ORAS : "") + " " +
                               (row.C_DE_LA_DATA.HasValue ? Convert.ToDateTime(row.C_DE_LA_DATA).ToString("dd/MMM/yyyy") : "") + " " +
                               (row.C_DE_LA_DATA.HasValue ? " - " + Convert.ToDateTime(row.C_PANA_LA_DATA).ToString("dd/MMM/yyyy") : "") + " " +
                               (!string.IsNullOrEmpty(row.C_ORAS) ? "Hotel: " + row.C_HOTEL : "") + " " +
                               (row.C_HOTEL_STELE.HasValue ? row.C_HOTEL_STELE.Value + "*" : "")
                               );
                form1.SetField("Servicii1", (row.C_NR_PERS.HasValue ? row.C_NR_PERS.Value.ToString() + " persoane " : "") +
                               (row.C_NR_ADULTI.HasValue ? "(" + row.C_NR_ADULTI.Value.ToString() + " adulti " : "") +
                               (row.C_NR_COPII.HasValue ? " + " + row.C_NR_COPII.Value.ToString() + " copii " : "") +
                               (row.C_NR_ADULTI.HasValue ? ")" : "")
                               );
                form1.SetField("Servicii2", row.C_MENTIUNI);
                form1.SetField("Pret", row.C_PRET.HasValue ? Convert.ToDecimal(row.C_PRET).ToString("F2") + " " + row.LIBRARIE.L_NUME : "");
                form1.SetField("Avans", row.C_AVANS.HasValue ? Convert.ToDecimal(row.C_AVANS).ToString("F2") + " " + row.LIBRARIE.L_NUME : "");
                form1.SetField("AvansData", row.C_DATA_DIFERENTA.HasValue ? Convert.ToDateTime(row.C_DATA_DIFERENTA).ToString("dd/MMM/yyyy") : "");
                form1.SetField("Factura", row.C_FACTURA);
                form1.SetField("Chitanta", row.C_CHITANTA);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                stamp1.Close();
                reader.Close();
            }

            return(File("~/Temp/" + id + ".pdf", "application/pdf"));
        }