// GET: Offerletters/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Offerletter offerletter = await db.Offerletter.FindAsync(id);

            if (offerletter == null)
            {
                return(HttpNotFound());
            }
            return(View(offerletter));
        }
        // GET: Offerletters/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Offerletter offerletter = await db.Offerletter.FindAsync(id);

            img       = offerletter.Files;
            imgtt     = offerletter.TT;
            imgrecipt = offerletter.Recipt;
            if (offerletter == null)
            {
                return(HttpNotFound());
            }
            return(View(offerletter));
        }
        public JsonResult InsertOffer(Offerletter Emp, ApplicationRecipt Recipt, Helper Help) // Record Insert
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Emp.Show = true;

                    db.Offerletter.Add(Emp);
                    db.SaveChanges();
                    Recipt.Date          = System.DateTime.Now;
                    Recipt.ApplicationNo = Emp.ApplicationNo;
                    Recipt.Leadger       = db.Ledgers.FirstOrDefault(x => x.ApplicationNo == Emp.ApplicationNo).LeaderNo;
                    Recipt.Type          = "Offer Letter";
                    Recipt.ReciptNo      = Help.recipt();
                    Recipt.Amount        = Emp.Amount;
                    Recipt.RecivedBy     = Help.Teacher();
                    db.ApplicationRecipts.Add(Recipt);
                    db.SaveChanges();
                    Process pr = db.Process.FirstOrDefault(x => x.ApplicationNo == Emp.ApplicationNo);
                    if (pr.Medical == false)
                    {
                        var Process = db.Process.SingleOrDefault(x => x.ApplicationNo == Emp.ApplicationNo);
                        if (Process != null)
                        {
                            Process.Offerletter = true;

                            db.SaveChanges();
                        }
                    }
                    transaction.Commit();
                    TempData["Success"] = "Data Save Sucessfully";
                    return(Json(Emp, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    string a = e.Message;
                    transaction.Rollback();
                    throw;
                }
            }
        }
        public async Task <ActionResult> Edit([Bind(Include = "Lid,ApplicationNo,Applied,Received,Cid,Oid,CCid,Yid,Mid,Amount,Show,Files,TT,Recipt")] Offerletter offerletter, HttpPostedFileBase file, HttpPostedFileBase tt, HttpPostedFileBase recipt, Helper Help, int college, int course, Offerletter off)
        {
            if (ModelState.IsValid)
            {
                offerletter.Files = file != null?Help.uploadfile(file) : img;

                offerletter.TT = tt != null?Help.uploadfile(tt) : imgtt;

                offerletter.Recipt = recipt != null?Help.uploadfile(recipt) : imgrecipt;

                // offerletter.Cid = countryid;
                offerletter.CCid            = course;
                offerletter.Oid             = college;
                offerletter.Mid             = off.Mid;
                offerletter.Yid             = off.Yid;
                db.Entry(offerletter).State = EntityState.Modified;
                await db.SaveChangesAsync();

                Application app = db.Applications.FirstOrDefault(x => x.ApplicationNo == offerletter.ApplicationNo);
                return(RedirectToAction("Create", "Application", new { id = app.InquiryId }));
            }
            return(View(offerletter));
        }