Beispiel #1
0
 public ActionResult edit(int id)
 {
     try
     {
         ViewBag.Employee_Profile          = dbcontext.Employee_Profile.Where(a => a.Active == true).ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });
         ViewBag.ManualPaymentTypes_Header = dbcontext.ManualPaymentTypes_Header.ToList().Select(m => new { Code = m.PaymentTypeCode + "-[" + m.PaymentTypeDesc + ']', ID = m.ID });
         ViewBag.id = id;
         var old_model = dbcontext.ManualPaymentTransactionEntry.FirstOrDefault(m => m.ID == id);
         var header    = new HeaderManual {
             ManualPaymentTransactionEntry = old_model, check_status = (check_status)old_model.TransactionStatus, Payment_Type_Source_Document = (Payment_Type_Source_Document)old_model.DocumentType
         };
         var old_details = dbcontext.ManualPaymentTransactionEntry_ExtendedFieldsDetail.Where(m => m.TransactionNumber == old_model.ID.ToString()).ToList();
         var new_model   = new VMs {
             ManualPaymentTransactionEntry_ExtendedFieldsDetail = old_details, Header = header
         };
         return(View(new_model));
     }
     catch (Exception)
     {
         return(RedirectToAction("index"));
     }
 }
Beispiel #2
0
        public ActionResult edit(VMs model, FormCollection form, string Command)
        {
            try
            {
                ViewBag.Employee_Profile          = dbcontext.Employee_Profile.Where(a => a.Active == true).ToList().Select(m => new { Code = m.Code + "-[" + m.Name + ']', ID = m.ID });
                ViewBag.ManualPaymentTypes_Header = dbcontext.ManualPaymentTypes_Header.ToList().Select(m => new { Code = m.PaymentTypeCode + "-[" + m.PaymentTypeDesc + ']', ID = m.ID });
                var H_  = dbcontext.ManualPaymentTransactionEntry.FirstOrDefault(m => m.ID == model.Header.ManualPaymentTransactionEntry.ID);
                var sta = dbcontext.status.FirstOrDefault(m => m.ID == H_.statID);
                if (sta.statu == Models.Infra.check_status.Approved || sta.statu == Models.Infra.check_status.Rejected || sta.statu == Models.Infra.check_status.Closed || sta.statu == Models.Infra.check_status.Recervied || sta.statu == Models.Infra.check_status.Canceled)
                {
                    TempData["message"] = HR.Resource.training.status_message;
                    return(RedirectToAction("index"));
                }
                ///update////
                var updated_model = dbcontext.ManualPaymentTransactionEntry.FirstOrDefault(m => m.ID == model.Header.ManualPaymentTransactionEntry.ID);

                updated_model.ExtendedFields_Code = model.Header.ManualPaymentTransactionEntry.ExtendedFields_Code;
                updated_model.TransactionNumber   = model.Header.ManualPaymentTransactionEntry.TransactionNumber;
                updated_model.Employee_Code       = model.Header.ManualPaymentTransactionEntry.Employee_Code;
                updated_model.ManualPaymentType   = model.Header.ManualPaymentTransactionEntry.ManualPaymentType;
                updated_model.TransactionDate     = model.Header.ManualPaymentTransactionEntry.TransactionDate;
                updated_model.EffectiveDate       = model.Header.ManualPaymentTransactionEntry.EffectiveDate;
                updated_model.CurrentYear         = model.Header.ManualPaymentTransactionEntry.CurrentYear;
                updated_model.PreviousYear        = model.Header.ManualPaymentTransactionEntry.PreviousYear;
                updated_model.FromDate            = model.Header.ManualPaymentTransactionEntry.FromDate;
                updated_model.ToDate               = model.Header.ManualPaymentTransactionEntry.ToDate;
                updated_model.TransactionNumber    = model.Header.ManualPaymentTransactionEntry.TransactionNumber;
                updated_model.PaidDate             = model.Header.ManualPaymentTransactionEntry.PaidDate;
                updated_model.PaidReferenceNumber  = model.Header.ManualPaymentTransactionEntry.PaidReferenceNumber;
                updated_model.ReferenceNumber      = model.Header.ManualPaymentTransactionEntry.ReferenceNumber;
                updated_model.ReferenceDescription = model.Header.ManualPaymentTransactionEntry.ReferenceDescription;
                updated_model.ReferenceNote        = model.Header.ManualPaymentTransactionEntry.ReferenceNote;
                updated_model.TransactionNote      = model.Header.ManualPaymentTransactionEntry.TransactionNote;
                updated_model.TransactionStatus    = model.Header.check_status.GetHashCode();
                updated_model.DocumentType         = model.Header.Payment_Type_Source_Document.GetHashCode();
                dbcontext.SaveChanges();
                ///////////delete//////////
                var update_details = dbcontext.ManualPaymentTransactionEntry_ExtendedFieldsDetail.Where(m => m.TransactionNumber == updated_model.ID.ToString()).ToList();
                dbcontext.ManualPaymentTransactionEntry_ExtendedFieldsDetail.RemoveRange(update_details);
                dbcontext.SaveChanges();
                ///////////////////add///////
                var codeid       = form["codeid"].Split(',');
                var SalaryDes    = form["SalaryDes"].Split(',');
                var ValueType    = form["ValueType"].Split(',');
                var DefaultValue = form["DefaultValue"].Split(',');

                for (var i = 0; i < codeid.Length; i++)
                {
                    if (codeid[i] != "")
                    {
                        var value       = double.Parse(DefaultValue[i]);
                        var valuetype   = ValueType[i];
                        var new_details = new ManualPaymentTransactionEntry_ExtendedFieldsDetail {
                            TransactionNumber = updated_model.ID.ToString(), Created_By = User.Identity.Name, Created_Date = DateTime.Now.Date, Detail_Code = codeid[i], Detail_Desc = SalaryDes[i], ValueType = valuetype, Value = value
                        };
                        dbcontext.ManualPaymentTransactionEntry_ExtendedFieldsDetail.Add(new_details);
                        dbcontext.SaveChanges();
                    }
                }
                if (Command == "Submit")
                {
                    return(RedirectToAction("Details", "ManualPaymentTransactionEntry", new { id = updated_model.ID, Trans = updated_model.TransactionNumber, Emp = updated_model.Employee_Code, Man = updated_model.ManualPaymentType, Source = updated_model.DocumentType }));//int.Parse(record.Employee_ProfileId)
                }
                ////////////////
                return(RedirectToAction("index"));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }