public ActionResult Create(PickupRequestVM v) { PickupRequestDAO _dao = new PickupRequestDAO(); int branchid = Convert.ToInt32(Session["CurrentBranchID"].ToString()); int depotId = Convert.ToInt32(Session["CurrentDepotID"].ToString()); int companyId = Convert.ToInt32(Session["CurrentCompanyID"].ToString()); int uid = Convert.ToInt32(Session["UserID"].ToString()); UserRegistration u = (from c in db.UserRegistrations where c.UserID == uid select c).FirstOrDefault(); int empid = u.UserID; string empname = u.UserName; InScanMaster _enquiry = new InScanMaster(); if (v.InScanID == 0) { int id = (from c in db.InScanMasters orderby c.InScanID descending select c.InScanID).FirstOrDefault(); _enquiry.InScanID = id + 1; _enquiry.EnquiryNo = _dao.GetMaxPickupRequest(companyId, branchid); // (id + 1).ToString(); _enquiry.ConsignmentNo = _dao.GetMaAWBNo(companyId, branchid); _enquiry.AcCompanyID = companyId; _enquiry.BranchID = branchid; _enquiry.DepotID = depotId; _enquiry.TransactionDate = DateTime.Now; _enquiry.DeviceID = "WebSite"; _enquiry.IsDeleted = false; int statustypeid = db.tblStatusTypes.Where(c => c.Name == "PICKUP REQUEST").FirstOrDefault().ID; _enquiry.StatusTypeId = statustypeid; //pickuprequest } else { _enquiry = db.InScanMasters.Find(v.InScanID); } _enquiry.DocumentSetupID = v.DocumentTypeId; _enquiry.PickupRequestDate = Convert.ToDateTime(v.EnquiryDate); _enquiry.CustomerID = v.CustomerID; _enquiry.ConsignorCountryName = v.ConsignorCountryName; _enquiry.ConsignorCityName = v.ConsignorCityName; _enquiry.ConsigneeLocationName = v.ConsigneeLocationName; _enquiry.ConsignorLocationName = v.ConsignorLocationName; _enquiry.ConsigneeCountryName = v.ConsigneeCountryName; _enquiry.ConsigneeCityName = v.ConsigneeCityName; _enquiry.Weight = Convert.ToDecimal(v.Weight); _enquiry.Consignee = v.Consignee; _enquiry.Consignor = v.Consignor; _enquiry.ConsignorAddress1_Building = v.ConsignorAddress; _enquiry.ConsignorAddress2_Street = v.ConsignorAddress1; _enquiry.ConsignorAddress3_PinCode = v.ConsignorAddress2; _enquiry.ConsigneeAddress1_Building = v.ConsigneeAddress; _enquiry.ConsigneeAddress2_Street = v.ConsigneeAddress1; _enquiry.ConsigneeAddress3_PinCode = v.ConsigneeAddress2; _enquiry.ConsignorPhone = v.ConsignorPhone; _enquiry.ConsigneePhone = v.ConsigneePhone; _enquiry.AssignedEmployeeID = v.EmployeeID; _enquiry.Remarks = v.Remarks; _enquiry.PickedUpEmpID = v.CollectedEmpID; _enquiry.PickedupDate = v.CollectedTime; //_enquiry.ShipmentType = v.ShipmentType; //if (v.vehreq == true) //{ // _enquiry.Vehicle = v.Vehicle; // _enquiry.VehicleID = v.VehicleID; //} _enquiry.ConsigneeContact = v.ConsigneeContact; _enquiry.ConsignorContact = v.ConsignorContact; _enquiry.EnteredByID = empid; //userid _enquiry.IsEnquiry = true; _enquiry.PickupReadyTime = v.ReadyTime; //_enquiry.OfficeTimeFrom = v.OfficeTimeFrom; //_enquiry.OfficeTimeTo = v.OfficeTimeTo; _enquiry.RequestSource = v.RequestSource; if (_enquiry.StatusTypeId == 1) { if (_enquiry.AssignedEmployeeID == null) { _enquiry.CourierStatusID = 1; } else if (_enquiry.AssignedEmployeeID != null && _enquiry.PickedUpEmpID == null) { _enquiry.CourierStatusID = 2; } //else if (_enquiry.PickedUpEmpID != null) //{ // _enquiry.PickupRequestStatusId = 3; //} else if (_enquiry.StatusTypeId == 1 && _enquiry.CourierStatusID == null) { _enquiry.CourierStatusID = 1; //request } } //db.CustomerEnquiries.Add(_enquiry); if (v.InScanID == 0) { db.InScanMasters.Add(_enquiry); db.SaveChanges(); // AWBTrackStatu _awbstatus = new AWBTrackStatu(); int? id = (from c in db.AWBTrackStatus orderby c.AWBTrackStatusId descending select c.AWBTrackStatusId).FirstOrDefault(); if (id == null) { id = 1; } else { id = id + 1; } _awbstatus.AWBTrackStatusId = Convert.ToInt32(id); _awbstatus.AWBNo = _enquiry.ConsignmentNo; _awbstatus.EntryDate = DateTime.Now; _awbstatus.InScanId = _enquiry.InScanID; _awbstatus.StatusTypeId = Convert.ToInt32(_enquiry.StatusTypeId); _awbstatus.CourierStatusId = Convert.ToInt32(_enquiry.CourierStatusID); _awbstatus.ShipmentStatus = db.tblStatusTypes.Find(_enquiry.StatusTypeId).Name; _awbstatus.CourierStatus = db.CourierStatus.Find(_enquiry.CourierStatusID).CourierStatus; _awbstatus.UserId = uid; db.AWBTrackStatus.Add(_awbstatus); db.SaveChanges(); // SaveConsignee(v); TempData["SuccessMsg"] = "You have successfully added Pickup Request."; } else { SaveConsignee(v); db.Entry(_enquiry).State = EntityState.Modified; db.SaveChanges(); TempData["SuccessMsg"] = "You have successfully updated Pickup Request."; } return(RedirectToAction("Index")); //} //else //{ // int uid = Convert.ToInt32(Session["UserID"].ToString()); // UserRegistration u = (from c in db.UserRegistrations where c.UserID == uid select c).FirstOrDefault(); // int empid = u.UserID; // string empname = u.UserName; // ViewBag.Country = db.CountryMasters.ToList(); // ViewBag.City = db.CityMasters.ToList(); // ViewBag.Location = db.LocationMasters.ToList(); // ViewBag.Vehicle = db.VehicleMasters.ToList(); // ViewBag.Employee = db.EmployeeMasters.ToList(); // ViewBag.Customer = db.CustomerMasters.ToList(); // ViewBag.RequestType = db.RequestTypes.ToList(); // ViewBag.empname = empname; // ViewBag.empid = empid; // PickupRequestDAO doa = new PickupRequestDAO(); // ViewBag.RequestNo = doa.GetMaxPickupRequest(); // return View(); //} }
public ActionResult Create(int id = 0) { int uid = Convert.ToInt32(Session["UserID"].ToString()); int branchid = Convert.ToInt32(Session["CurrentBranchID"].ToString()); int depotId = Convert.ToInt32(Session["CurrentDepotID"].ToString()); int companyId = Convert.ToInt32(Session["CurrentCompanyID"].ToString()); ViewBag.Vehicle = db.VehicleMasters.ToList(); ViewBag.Employee = db.EmployeeMasters.ToList(); ViewBag.Customer = db.CustomerMasters.ToList(); ViewBag.RequestType = db.RequestTypes.ToList(); ViewBag.DocumentType = db.tblDocumentTypes.ToList(); ViewBag.PaymentMode = db.tblPaymentModes.ToList(); //ViewBag.PickupRequestStatus = db.PickUpRequestStatus.ToList(); ViewBag.PickupRequestStatus = db.CourierStatus.Where(cc => cc.StatusTypeID == 1).ToList(); ViewBag.PickupSubReason = db.SubStatus.ToList(); PickupRequestVM v = new PickupRequestVM(); UserRegistration u = (from c in db.UserRegistrations where c.UserID == uid select c).FirstOrDefault(); int empid = u.UserID; string empname = u.UserName; ViewBag.empname = empname; ViewBag.empid = empid; if (id == 0) { PickupRequestDAO doa = new PickupRequestDAO(); ViewBag.RequestNo = doa.GetMaxPickupRequest(companyId, branchid); ViewBag.StatusId = 1; int Customerid = 0; if (Session["UserType"].ToString() == "Customer") { Customerid = Convert.ToInt32(Session["CustomerId"].ToString()); v.CustomerID = Customerid; var _cust = db.CustomerMasters.Find(Customerid); v.CustomerName = _cust.CustomerName; v.CustomerCode = _cust.CustomerCode; v.Consignor = _cust.CustomerName; v.ConsignorPhone = _cust.Phone; v.OfficeTimeFrom = _cust.OfficeOpenTime; v.OfficeTimeTo = _cust.OfficeCloseTime; v.ConsignorAddress = _cust.Address1; v.ConsignorAddress1 = _cust.Address2; v.ConsignorAddress2 = _cust.Address3; v.ConsignorCountryName = _cust.CountryName; v.ConsignorCityName = _cust.CityName; v.ConsignorContact = _cust.ContactPerson; } } else { v = GetPickupRequestDetail(id); ViewBag.AWBNo = v.AWBNo; ViewBag.StatusId = v.PickupRequestStatusId; ViewBag.SubReasonStatusId = v.SubReasonId; ViewBag.Status = db.CourierStatus.Where(cc => cc.CourierStatusID == v.PickupRequestStatusId).FirstOrDefault().CourierStatus; } return(View(v)); }