Exemplo n.º 1
0
        public Operation Delete(AnFVoucher obj)
        {
            Operation objOperation = new Operation { Success = true, OperationId = obj.Id };
            _voucherRepository.Delete(obj);

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception)
            {

                objOperation.Success = false;
            }
            return objOperation;
        }
 public int UpdateVoucher(AnFVoucher v)
 {
     int ret;
     ret= _AnFVoucherRepository.UpdateEntity(v);
     return ret;
 }
        public int SaveVoucher(AnFVoucher v)
        {
            int Id = _AnFVoucherRepository.AddEntity(v);

            try
            {
                //  _UnitOfWork.Commit();
            }
            catch (Exception ex)
            {
            }
            return Id;
        }
 public AnFVoucher GetAnfVoucherById(int Id)
 {
     try
     {
         AnFVoucher record = null;
         DataTable dt = GetAnfVoucher(Id);
         if (dt != null && dt.Rows.Count > 0)
         {
             record = new AnFVoucher();
             record = (AnFVoucher)Helper.FillTo(dt.Rows[0], typeof(AnFVoucher));
         }
         return record;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
        public Operation SaveVoucher(AnFVoucher obj, Operation objOperation, System.Data.Entity.DbContextTransaction dbContextTransaction)
        {
            try
            {
                bool update = false;
                long Id = 0;
                if (obj.Id <= 0)
                {
                    Id = _voucherRepository.AddEntity(obj);
                }
                else
                {
                    Id = obj.Id;
                    update = true;
                }

                if (Id > 0)
                {
                    objOperation.OperationId = Id;

                    var existingDetailList = _voucherDetailRepository.GetAll();
                    if (existingDetailList != null && existingDetailList.Count() > 0)
                    {
                        existingDetailList = existingDetailList.Where(i => i.AnFVoucherId == Id).ToList();
                    }

                    IList<AnFVoucherDetail> newdetailList = new List<AnFVoucherDetail>();
                    //obj.AnFVoucherDetails.First().Id = 1561;
                    //Delete detail
                    foreach (AnFVoucherDetail delete in existingDetailList)
                    {
                        AnFVoucherDetail exists = null;
                        try
                        {
                            exists = obj.AnFVoucherDetails.Where(i => i.Id == delete.Id).FirstOrDefault();
                        }
                        catch(Exception ex)
                        {

                        }
                        if(exists == null)
                        {
                            _voucherDetailRepository.Delete(delete);
                        }
                    }

                    //add/update detail
                    foreach (AnFVoucherDetail detail in obj.AnFVoucherDetails)
                    {
                        detail.AnFVoucherId = int.Parse(objOperation.OperationId.ToString());
                        if (detail.Id <= 0)
                        {
                            //detail.SubVoucherNumber = "MLP-JV-001-2/06-14-2";
                            newdetailList.Add(detail);
                        }
                        else
                        {
                            //detail.SubVoucherNumber = "MLP-JV-001-1/06-14-2";
                            _voucherDetailRepository.Modified(detail);
                        }
                    }
                    //Add offer detail list - new offer details
                    if (newdetailList != null && newdetailList.Count > 0)
                    {
                        _voucherDetailRepository.AddEntityList(newdetailList);
                    }

                    if(update)
                    {
                        _voucherRepository.Modified(obj);
                    }
                    _voucherRepository.SaveChanges();

                    _voucherDetailRepository.SaveChanges();
                    try
                    {
                        _voucherRepository.Commit(dbContextTransaction);
                        objOperation.Success = true;
                    }
                    catch (Exception ex)
                    {
                        objOperation.Message = ex.Message;
                        throw ex;
                    }
                }
                else
                {
                    objOperation.Success = false;
                }
            }
            catch (Exception ex)
            {
                objOperation.Success = false;
                _voucherRepository.Rollback(dbContextTransaction);
            }
            return objOperation;
        }
Exemplo n.º 6
0
        public Operation Save(AnFVoucher obj)
        {
            Operation objOperation = new Operation { Success = false };

            using (var dbContextTransaction = _voucherRepository.BeginTransaction())
            {
                objOperation = SaveVoucher(obj, objOperation, dbContextTransaction);
            }
            return objOperation;
        }
        public ActionResult SaveVoucher(AnFVoucher obj)
        {
            Operation objOperation = new Operation { Success = false };

            if (ModelState.IsValid)
            {
                //obj.Id = 332;
                //obj.VoucherNumber = "MLP-JV-001-2/06-14";
                if (obj.Id == 0)
                {
                    //if ((bool)Session["Add"])
                    //{
                    int officeId = obj.SlsOfficeId != null ? (int)obj.SlsOfficeId : 0;
                    string typeStr = Enum.GetName(typeof(VoucherType), obj.Type);
                    obj.VoucherNumber = GetVoucherNo(obj.CmnCompanyId, obj.Type, typeStr, officeId, obj.CmnFinancialYearId, obj.Date);
                    foreach (var detail in obj.AnFVoucherDetails)
                    {
                        detail.SubVoucherNumber = obj.VoucherNumber + "-" + detail.VoucherSerial;
                    }
                    obj.IsPosted = false;
                    obj.PostedBy = userId;
                    obj.PostedDate = DateTime.Now.Date;
                    obj.CreatedBy = userId;
                    obj.CreatedDate = DateTime.Now.Date;

                    objOperation = _VoucherService.Save(obj);
                    //}
                    //else { objOperation.OperationId = -1; }

                }
                else
                {
                    //if ((bool)Session["Edit"])
                    //{
                    obj.ModifiedBy = userId;
                    obj.ModifiedDate = DateTime.Now.Date;
                    foreach (var detail in obj.AnFVoucherDetails)
                    {
                        detail.SubVoucherNumber = obj.VoucherNumber + "-" + detail.VoucherSerial;
                    }

                    objOperation = _VoucherService.Save(obj);
                    //}
                    //else { objOperation.OperationId = -2; }
                }
            }

            return Json(objOperation, JsonRequestBehavior.DenyGet);

            //return Json(new { Success= true }, JsonRequestBehavior.DenyGet);
        }