コード例 #1
0
 public ActionResult AddorEdit(Item item)
 {
     try
     {
         if (item.Upload_Image != null)
         {
             string fileName  = Path.GetFileNameWithoutExtension(item.Upload_Image.FileName);
             string extension = Path.GetExtension(item.Upload_Image.FileName);
             fileName        = fileName + DateTime.Now.ToString("yyMMddmmssfff") + extension;
             item.Item_Image = "~/Files/Items/" + fileName;
             item.Upload_Image.SaveAs(Path.Combine(Server.MapPath("~/Files/Items/"), fileName));
         }
         using (OVODEntities5 db = new OVODEntities5())
         {
             if (item.Item_Id == 0)
             {
                 db.Items.Add(item);
                 item.Item_Date   = DateTime.Now;
                 item.Item_Expiry = DateTime.Now.AddYears(2);
                 db.SaveChanges();
             }
             else
             {
                 item.Item_Date       = DateTime.Now;
                 item.Item_Expiry     = DateTime.Now.AddYears(2);
                 db.Entry(item).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
         //ViewRenderer vw = new ViewRenderer();
         //return Json(new { success = true, html = vw.RenderPartialView("ViewAll", getAllItem()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet);
         return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", getAllItem()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #2
0
        public ActionResult PayadjSave(string PA_DOCNO, string PA_DOCDATE, string PA_HEADER, string PA_TITLE, string PA_MONTH, string PA_YEAR, DT_HRPAYADJ[] det)
        {
            int DocId;

            if (PA_DOCNO != null || PA_DOCDATE != null || PA_MONTH != null || PA_YEAR != null)
            {
                using (var context = new OVODEntities5())
                {
                    using (var dbcxtransaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            var DocData = context.HD_HRPAYADJ.Where(x => x.PA_DOCNO == PA_DOCNO).FirstOrDefault();
                            if (DocData != null)
                            {
                                //HD_HRPAYADJ hd = new HD_HRPAYADJ()
                                //{
                                //    PA_DOCDATE = Convert.ToDateTime(PA_DOCDATE),
                                //    PA_HEADER = PA_HEADER,
                                //    PA_TITLE = PA_TITLE,
                                //    PA_MONTH = PA_MONTH,
                                //    PA_YEAR = PA_YEAR
                                //};
                                DocData.PA_DOCDATE           = Convert.ToDateTime(PA_DOCDATE);
                                DocData.PA_HEADER            = PA_HEADER;
                                DocData.PA_TITLE             = PA_TITLE;
                                DocData.PA_MONTH             = PA_MONTH;
                                DocData.PA_YEAR              = PA_YEAR;;
                                context.Entry(DocData).State = EntityState.Modified;
                                context.SaveChanges();
                                DocId = context.HD_HRPAYADJ.Where(x => x.PA_DOCNO == PA_DOCNO).Select(a => a.PA_ID).Single();

                                //DT_HRPAYADJ details = new DT_HRPAYADJ { PAD_ID = DocId };
                                //context.Entry(details).State = EntityState.Deleted;
                                var items = context.DT_HRPAYADJ.Where(b => b.PA_ID == DocId);
                                foreach (var item in items)
                                {
                                    context.DT_HRPAYADJ.Remove(item);
                                }

                                context.SaveChanges();

                                if (DocId > 0)
                                {
                                    foreach (var item in det)
                                    {
                                        DT_HRPAYADJ s = new DT_HRPAYADJ()
                                        {
                                            PA_ID       = DocId,
                                            EM_ID       = item.EM_ID,
                                            TT_ID       = item.TT_ID,
                                            PAD_QTY     = item.PAD_QTY,
                                            PAD_RATE    = item.PAD_RATE,
                                            PAD_AMT     = (item.PAD_RATE * item.PAD_QTY),
                                            PAD_REMARKS = item.PAD_REMARKS
                                        };
                                        context.DT_HRPAYADJ.Add(s);
                                    }
                                    context.SaveChanges();
                                    dbcxtransaction.Commit();
                                    result = "Success! Document Update Completed.";
                                }
                                else
                                {
                                    dbcxtransaction.Rollback();
                                    result = "Invalid Code!";
                                }
                            }
                            else
                            {
                                HD_HRPAYADJ hd = new HD_HRPAYADJ()
                                {
                                    PA_DOCNO   = PA_DOCNO,
                                    PA_DOCDATE = Convert.ToDateTime(PA_DOCDATE),
                                    PA_HEADER  = PA_HEADER,
                                    PA_TITLE   = PA_TITLE,
                                    PA_MONTH   = PA_MONTH,
                                    PA_YEAR    = PA_YEAR
                                };
                                context.HD_HRPAYADJ.Add(hd);
                                context.SaveChanges();
                                DocId = hd.PA_ID;

                                if (DocId > 0)
                                {
                                    foreach (var item in det)
                                    {
                                        DT_HRPAYADJ s = new DT_HRPAYADJ()
                                        {
                                            PA_ID       = DocId,
                                            EM_ID       = item.EM_ID,
                                            TT_ID       = item.TT_ID,
                                            PAD_QTY     = item.PAD_QTY,
                                            PAD_RATE    = item.PAD_RATE,
                                            PAD_AMT     = (item.PAD_RATE * item.PAD_QTY),
                                            PAD_REMARKS = item.PAD_REMARKS
                                        };
                                        context.DT_HRPAYADJ.Add(s);
                                    }
                                    context.SaveChanges();
                                    dbcxtransaction.Commit();
                                    result = "Success! Document Creation Completed.";
                                }
                                else
                                {
                                    dbcxtransaction.Rollback();
                                    result = "Invalid Code!";
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            result = ex.ToString();
                            dbcxtransaction.Rollback();
                        }
                    }
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }