public Boolean EditPurchaseRequisitionNoteSumamry(PurchaseRequisitionNoteModel prnModel)
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {

                    var data =
                        _context.PurchaseRequisitionNotes.FirstOrDefault(
                            a => a.PurchaseRequisitionNoteId == prnModel.PurchaseRequisitionNoteId);

                    if (data != null)
                    {
                        data.PrnNumber = prnModel.PrnNumber;
                        data.CreatedBy = prnModel.PrnNumber;
                        data.Reason = prnModel.Reason;
                        data.IsApprovedByGM = prnModel.IsApprovedByGM;
                        data.ApproverId = prnModel.ApproverId;
                        data.DateOfApproved = prnModel.DateOfApproved;
                    }

                    _context.Entry(data).State = EntityState.Modified;
                    _context.SaveChanges();
                    //dispatchOrderModel.DispatchOrderId =data.DispatchOrderId;
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return false; //new DispatchOrderModel();
                }
            }
        }
 private void btnApproved_Click_1(object sender, EventArgs e)
 {
     var model = new PurchaseRequisitionNoteModel()
     {
         PurchaseRequisitionNoteId = Convert.ToInt32(LVPRn.SelectedItem.Value),
         IsApprovedByGM = 1,
     };
     _purchaseRequisitionNoteService.EditPurchaseRequisitionNoteSumamry(model);
     RadMessageBox.Show("Approved Success");
     grdPRN.Rows.Clear();
     grdPRN.Refresh();
     Listview();
     notify();
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            var model = new PurchaseRequisitionNoteModel()
            {
                PrnNumber = Convert.ToInt32(txtPrn.Text),
                EngPRNDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()),
                NepPRNDate = ucENCalendar1.NepaliDate,
                CreatedBy = 1,
                CreatedDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()),

            };
            model.PrnDetailModels = datafunc();
             _purchaseRequisitionNoteService.SavePurchaseRequisitionNote(model);
            RadMessageBox.Show("Successfully Added");
            Notify();
            grdDisplay.Rows.Clear();
            grdDisplay.Refresh();
            txtQuantity.Text = "";
        }
        private PurchaseRequisitionNoteModel SavePurchaseRequisitionNoteSumamry(PurchaseRequisitionNoteModel PRNmodel)
        {
            using (_context = new HSSNInventoryEntities())
            {
                try
                {
                    var purchaseRequisitionNoteModel = new PurchaseRequisitionNote()
                    {
                      PrnNumber = PRNmodel.PrnNumber,
                      CreatedBy = PRNmodel.PrnNumber,
                      EngPRNDate = PRNmodel.EngPRNDate,
                      NepPRNDate = PRNmodel.NepPRNDate,
                      CreatedDate = PRNmodel.CreatedDate,
                      Reason = PRNmodel.Reason,
                      IsApprovedByGM = PRNmodel.IsApprovedByGM,
                      ApproverId = PRNmodel.ApproverId,
                      DateOfApproved =PRNmodel.DateOfApproved

                    };
                    _context.Entry(purchaseRequisitionNoteModel).State = EntityState.Added;
                    _context.SaveChanges();
                    PRNmodel.PurchaseRequisitionNoteId = purchaseRequisitionNoteModel.PurchaseRequisitionNoteId;
                    return PRNmodel;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return new PurchaseRequisitionNoteModel();
                }
            }
        }
        public bool SavePurchaseRequisitionNote(PurchaseRequisitionNoteModel purchaseRequisitionNoteModel)
        {
            try
                {
                    if (purchaseRequisitionNoteModel.PurchaseRequisitionNoteId == 0)
                    {
                        using (var scope=new TransactionScope())
                        {
                            //write code for new save data

                            var purchaseRequisitionNoteId=SavePurchaseRequisitionNoteSumamry(purchaseRequisitionNoteModel)
                                .PurchaseRequisitionNoteId;

                                SavePrnDetails(purchaseRequisitionNoteModel.PrnDetailModels,
                                    purchaseRequisitionNoteId);
                                //update serical number
                                _commonService.UpdateSerialNumberVoucherType("PRN");
                                scope.Complete();

                        }
                    }
                    else
                    {
                        //write code for edited data
                        using (var scope=new TransactionScope())
                        {
                            if (EditPurchaseRequisitionNoteSumamry(purchaseRequisitionNoteModel) == true)
                            {
                                if (
                                    DeletePrnDetailByPurchaseRequisitionNoteId(
                                        purchaseRequisitionNoteModel.PurchaseRequisitionNoteId))
                                {
                                    SavePrnDetails(purchaseRequisitionNoteModel.PrnDetailModels,
                                        purchaseRequisitionNoteModel.PurchaseRequisitionNoteId);
                                }
                            }

                            scope.Complete();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            return true;
        }
        public PurchaseRequisitionNoteModel GetProductRequisitionNoteDetailByPurchaseRequisitionNoteId(int purchaseRequisitionNoteId)
        {
            using (_context=new HSSNInventoryEntities())
            {
                try
                {
                    var prnModel=
                        _context.PurchaseRequisitionNotes.Where(
                            a => a.PurchaseRequisitionNoteId == purchaseRequisitionNoteId)
                            .Select(PRNmodel => new PurchaseRequisitionNoteModel()
                            {
                                PurchaseRequisitionNoteId = PRNmodel.PurchaseRequisitionNoteId,
                                PrnNumber = PRNmodel.PrnNumber,
                                CreatedBy = PRNmodel.PrnNumber,
                                Reason = PRNmodel.Reason,
                                IsApprovedByGM = PRNmodel.IsApprovedByGM,
                                ApproverId = PRNmodel.ApproverId,
                                DateOfApproved = PRNmodel.DateOfApproved

                            }).FirstOrDefault();
                    var prnDetailModel = (from a in _context.PRNDetails
                        join b in _context.ProductionMaterials on a.ProductionMaterialId equals b.ProductionMaterialId
                        where a.PurchaseRequisitionNoteId == purchaseRequisitionNoteId
                        select new PRNDetailModel()
                        {
                            PRNDetailId = a.PRNDetailId,
                            PurchaseRequisitionNoteId = purchaseRequisitionNoteId,
                            ProductionMaterialId = a.ProductionMaterialId,
                            PurchaseQuantity = a.PurchaseQuantity,
                            UnitOfMeasurementId = a .UnitOfMeasurementId,
                            MaterialName = b.MaterialName
                        }).ToList();

                    var model = new PurchaseRequisitionNoteModel();
                    model = prnModel;
                    model.PrnDetailModels = prnDetailModel;
                    return model;
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }