public bool AddPurchaseTransDocument(PurchaseTransactionDocument purtransdoc)
 {
     try {
      purtransdoc.State=ObjectState.Added;
      _rep.AddOperation(purtransdoc);
      purtransdoc.State = ObjectState.Unchanged;
      return true;
     }catch(Exception ex){
         var msg = ex.Message;
         return false;
     }
 }
 public bool UpdatePurchaseTransDocument(PurchaseTransactionDocument purtransdoc)
 {
     try
     {
         purtransdoc.State = ObjectState.Modified;
         _rep.UpdateOperation(purtransdoc);
         return true;
     }
     catch (Exception ex)
     {
         var msg = ex.Message;
         return false;
     }
 }
예제 #3
0
        public ActionResult PostPurchase(InventoriesEditBill purchase)
        {
            int postcount = Request.Form.GetValues("ItemId").Count();
            if (postcount > 0)
            {
                var user = _uService.GetSingleUserByEmail(HttpContext.User.Identity.Name);
                var logObj = _companyViewLog.GetLastViewCompanyByUserId(user.Id);
                var companyId = 0;
                if (logObj.CompanyId != null) companyId = (int)logObj.CompanyId;
                var empObj = empSer.GetEmployeeByUserId(user.Id);
                purchase.PurchaseTransactions.EmployeeId = empObj.Id;
                purchase.PurchaseTransactions.CompanyId = companyId;

                if (ptSer.AddPurchaseTransaction(purchase.PurchaseTransactions))
                {

                    int counter = 0;
                    var items = Request.Form.GetValues("ItemId");
                    var descriptions = Request.Form.GetValues("description");
                    var quantities = Request.Form.GetValues("quantity");
                    var unitPrices = Request.Form.GetValues("unitPrice");
                    var CoaIds = Request.Form.GetValues("CoaId");
                    var TaxIds = Request.Form.GetValues("TaxId");

                    for (var i = 0; i < postcount; i++)
                    {
                        PurchaseTransactionDetail ptd = new PurchaseTransactionDetail();

                        ptd.ItemId = int.Parse(items[i]);
                        ptd.Quantity = double.Parse(quantities[i]);
                        ptd.TaxId = int.Parse(TaxIds[i]);
                        ptd.UnitPrice = double.Parse(unitPrices[i]);
                        ptd.Description = descriptions[i];
                        ptd.CoaId = int.Parse(CoaIds[i]);
                        ptd.PurchaseTransactionId = purchase.PurchaseTransactions.Id;
                        ptdSer.AddPurchaseTransDetailService(ptd);
                        counter++;
                    }
                    if (postcount == counter)
                    {
                        string data = Request.Form["note_data"];

                        if (Request.Form["note_data"] != "")
                        {
                            JArray noteData = JArray.Parse(data);

                            for (int i = 0; i < noteData.Count(); i++)
                            {
                                var PtDoc = new PurchaseTransactionDocument();

                                PtDoc.CreatedDate = Convert.ToDateTime(noteData[i]["date"].ToString());
                                PtDoc.Description = noteData[i]["des"].ToString();
                                PtDoc.DocumentType = noteData[i]["type"].ToString();
                                PtDoc.EmployeeId = empObj.Id;
                                PtDoc.PurchaseTransactionId = purchase.PurchaseTransactions.Id;
                                ptDocSer.AddPurchaseTransDocument(PtDoc);
                            }
                        }
                        string documentName;
                        string documentLocation;
                        for (int i = 0; i < Request.Files.Count; i++)
                        {
                            if ("documentLocation[]" == Request.Files.GetKey(i))
                            {
                                documentName = "Document_" + purchase.PurchaseTransactions.Id + "_" + i + Path.GetRandomFileName() + Path.GetExtension(Request.Files[i].FileName);
                                documentLocation = Server.MapPath("~/Uploads/" + empObj.Companies.TradingName.Replace(" ", "_") + "/PurcahsesTransactionDocuments/");
                                if (fileUpload(Request.Files[i], documentName, documentLocation))
                                {
                                    var PtDoc = new PurchaseTransactionDocument();
                                    PtDoc.CreatedDate = DateTime.Now;
                                    PtDoc.DocumentType = "File";
                                    PtDoc.EmployeeId = empObj.Id;
                                    PtDoc.PurchaseTransactionId = purchase.PurchaseTransactions.Id;
                                    PtDoc.FileLocation = "Uploads/" + empObj.Companies.TradingName.Replace(" ", "_") + "/PurcahsesTransactionDocuments/" + documentName;
                                    ptDocSer.AddPurchaseTransDocument(PtDoc);
                                }
                            }

                        }
                        TempData["success"] = "Bill Created Successfully";

                    }
                    else
                    {
                        TempData["success"] = "One or more items could not be added";
                    }

                }
                else
                {
                    TempData["success"] = "Error in bill genaration";
                }

            }
            else
            {
                TempData["success"] = "No Item was selected";
            }

            return RedirectToAction("EditBill", "Purchases");
        }