public static SelectList AddressBookList(object selectedItem) { ILibrary <AddressBook> lib = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <AddressBook> result = lib.GetAll(); SelectList sList = new SelectList(result, "ID", "Address1", selectedItem); return(sList); }
public static AddressBook GetAddressByID(string id) { int addressID = 0; int.TryParse(id, out addressID); ILibrary <AddressBook> lib = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); return(lib.GetByID(addressID.ToString())); }
protected override void SaveChildEntities(string[] childEntityList, Party entity) { foreach (string ChildEntity in childEntityList) { switch (ChildEntity) { #region /* Case Statements - All child grids */ case "AddressBook": if (Session[ChildEntity] != null) { ILibrary <AddressBook> contactLibrary = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <AddressBook> resultList = (IList <AddressBook>)Session[ChildEntity]; //if (resultList.Count() == 1 || resultList.Count(o => o.Primary_Flag == true) <= 0) // resultList.FirstOrDefault().Primary_Flag = true; foreach (AddressBook contact in resultList) { contact.Party = new Party() { ID = entity.ID }; contactLibrary.Add(contact); } } break; case "Bank": if (Session[ChildEntity] != null) { ILibrary <Bank> contactLibrary = new BankLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Bank> resultList = (IList <Bank>)Session[ChildEntity]; foreach (Bank contact in resultList) { contact.Party = new Party() { ID = entity.ID }; contactLibrary.Add(contact); } } break; case "Bin": if (Session[ChildEntity] != null) { ILibrary <Bin> contactLibrary = new BinLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Bin> resultList = (IList <Bin>)Session[ChildEntity]; foreach (Bin contact in resultList) { contact.Party = new Party() { ID = entity.ID }; contactLibrary.Add(contact); } } break; case "Contact": if (Session[ChildEntity] != null) { ILibrary <Contact> contactLibrary = new ContactLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Contact> resultList = (IList <Contact>)Session[ChildEntity]; foreach (Contact contact in resultList) { contact.Party = new Party() { ID = entity.ID }; contactLibrary.Add(contact); } } break; case "Note": if (Session[ChildEntity] != null) { ILibrary <Note> contactLibrary = new NoteLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Note> resultList = (IList <Note>)Session[ChildEntity]; foreach (Note contact in resultList) { contact.Party = new Party() { ID = entity.ID }; contactLibrary.Add(contact); } } break; #endregion } } }
//public Party SaveParty(string licenseNo, string name,string state,string loginUser,string imageRefId) { public Party SaveParty(Party party, AddressBook address) { Party entity = null; // Save Party if (party != null) { PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); entity = partyLib.GetByID(party.ID.ToString()); if (entity == null || entity.ID <= 0) { entity = new Party(); } entity.License_No = party.License_No; entity.Party_Name = party.Party_Name; entity.Party_Short_Name = party.Party_Short_Name; entity.State = party.State; entity.Created_By = party.Created_By; entity.Created_Date = DateTime.Now; entity.Active_Ind = true; entity.IsActive = true; entity.Updated_By = party.Updated_By; entity.Last_Updated_Date = DateTime.Now; entity.Party_Type = "Individual"; entity.LicenseImageRefId = party.LicenseImageRefId; entity.Party_DOB = party.Party_DOB; entity.ACLicense_ID = party.ACLicense_ID; entity.ThumbImage1RefId = party.ThumbImage1RefId; entity.ThumbImage2RefId = party.ThumbImage2RefId; entity.PhotoRefId = party.PhotoRefId; entity.SignatureImageRefId = party.SignatureImageRefId; entity.VehicleImageRegId = party.VehicleImageRegId; entity.CashCardImageRefId = party.CashCardImageRefId; if (entity == null || entity.ID <= 0) { entity = partyLib.Add(entity); } else { entity = partyLib.Modify(entity); } // Save Address if (address != null) { AddressBookLibrary addressLib = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); AddressBook addressBook = addressLib.GetPrimaryAddressesByPartyId(entity.ID); if (addressBook == null || addressBook.ID <= 0) { addressBook = new AddressBook(); } addressBook.Party = entity; addressBook.Address1 = address.Address1; addressBook.City = address.City; addressBook.State = party.State; addressBook.Zip_Code = address.Zip_Code; addressBook.Country = address.Country; addressBook.Primary_Flag = true; addressBook.Address_Type = address.Address_Type; addressBook.Created_By = party.Created_By; addressBook.Created_Date = DateTime.Now; addressBook.Active_Ind = true; addressBook.Updated_By = party.Updated_By; addressBook.Last_Updated_Date = DateTime.Now; if (addressBook == null || addressBook.ID <= 0) { addressLib.Add(addressBook); } else { addressLib.Modify(addressBook); } } } return(entity); }
public JsonResult _PartyById(string id) { int intID; bool isParse = int.TryParse(id, out intID); Party party = null; AddressBook address = null; if (isParse) { party = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(id); address = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetPrimaryAddressesByPartyId(intID); } int partyId = 0; string partyName, photoRefId, thumb1RefId, thumb2RefId, signatureRefId, licenseRefId, cashCardRefId; partyName = photoRefId = thumb1RefId = thumb2RefId = signatureRefId = licenseRefId = cashCardRefId = ""; string state = " "; string make = ""; string model = ""; string vehiclePlateNo = ""; string vehicleYear = ""; string vehicleSate = ""; string color = ""; string address1, city, country, zip, addressType, dob, acLicenseId, licenseNo; address1 = city = country = zip = addressType = dob = acLicenseId = licenseNo = ""; if (party != null) { partyName = party.Party_Name; partyId = party.ID; state = party.State == null ? " " : party.State; dob = Convert.ToString(party.Party_DOB); acLicenseId = Convert.ToString(party.ACLicense_ID); licenseNo = Convert.ToString(party.License_No); photoRefId = Convert.ToString(party.PhotoRefId); thumb1RefId = Convert.ToString(party.ThumbImage1RefId); thumb2RefId = Convert.ToString(party.ThumbImage2RefId); signatureRefId = Convert.ToString(party.LicenseImageRefId); licenseRefId = Convert.ToString(party.SignatureImageRefId); cashCardRefId = Convert.ToString(party.CashCardImageRefId); Scale scale = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetLastTicketByPartyId(party.ID, new string[] { "Party_ID" }); if (scale != null) { make = scale.Make; model = scale.Model; vehiclePlateNo = scale.Vehicle_Plate_No; vehicleYear = scale.Vehicle_Year; vehicleSate = scale.Plate_State; color = scale.Color; } } if (address != null) { address1 = address.Address1; city = address.City; country = address.Country; zip = address.Zip_Code; addressType = address.Address_Type; // state = address.State == null ? " " : address.State; } var data = new { ID = partyId, Name = partyName, State = state, LicenseNo = licenseNo, Address1 = address1, City = city, Country = country, Zip = zip, AddressType = addressType, DOB = dob, ACLicenseId = acLicenseId, PhotoRefId = photoRefId, Thumb1RefId = thumb1RefId, Thumb2RefId = thumb2RefId, SignatureRefId = signatureRefId, LicenseRefId = licenseRefId, CashCardRefId = cashCardRefId, Make = make, Model = model, VehiclePlateNo = vehiclePlateNo, VehicleYear = vehicleYear, Color = color, VehicleLicenseState = vehicleSate }; return(Json(data, JsonRequestBehavior.AllowGet)); }
protected override void DeleteChildEntities(string[] childEntityList, string parentID) { foreach (string ChildEntity in childEntityList) { switch (ChildEntity) { #region /* Case Statements - All child grids */ case "AddressBook": if (Convert.ToInt32(parentID) > 0) { AddressBookLibrary library = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <AddressBook> resultList = library.GetAllByParentID(Convert.ToInt32(parentID)); foreach (AddressBook entity in resultList) { library.Delete(entity.ID.ToString()); } } break; case "Bank": if (Convert.ToInt32(parentID) > 0) { BankLibrary library = new BankLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Bank> resultList = library.GetAllByParentID(Convert.ToInt32(parentID)); foreach (Bank entity in resultList) { library.Delete(entity.ID.ToString()); } } break; case "Bin": if (Convert.ToInt32(parentID) > 0) { BinLibrary lib = new BinLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Bin> resultList = lib.GetAllByParentID(Convert.ToInt32(parentID)); foreach (Bin bin in resultList) { lib.Delete(bin.ID.ToString()); } } break; case "Contact": if (Convert.ToInt32(parentID) > 0) { ContactLibrary lib = new ContactLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Contact> resultList = lib.GetAllByParentID(Convert.ToInt32(parentID)); foreach (Contact contact in resultList) { lib.Delete(contact.ID.ToString()); } } break; case "Note": if (Convert.ToInt32(parentID) > 0) { NoteLibrary lib = new NoteLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Note> resultList = lib.GetAllByParentID(Convert.ToInt32(parentID)); foreach (Note note in resultList) { lib.Delete(note.ID.ToString()); } } break; #endregion } } }
public AddressBook GetAddressByPartyId(int partyId) { AddressBookLibrary lib = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); return(lib.GetPrimaryAddressesByPartyId(partyId)); }
public HttpResponseMessage SaveTicket([FromBody] Ticket value) { try { if (value.Scale == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // Start transaction. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { smART.ViewModel.Scale newScale = new Scale(); // Add new party if already exists if (!string.IsNullOrEmpty(value.Scale.License_No)) { PartyLibrary partyLib = new PartyLibrary(ConString); Party party = partyLib.GetByLicenseNo(value.Scale.License_No); if (party != null) { newScale.Party_ID = party; } else { // Add new party party = new Party(); party.Party_Name = value.Scale.Customer_Name; party.Party_Short_Name = value.Scale.Customer_Name; party.License_No = value.Scale.License_No; party.Party_Type = "Individual"; party.Created_By = value.Scale.Created_By; party.Updated_By = value.Scale.Created_By; party.Created_Date = value.Scale.Created_Date; party.Last_Updated_Date = value.Scale.Created_Date; party.Active_Ind = true; party.IsActive = true; party.State = !string.IsNullOrEmpty(value.Scale.Customer_State) ? value.Scale.Customer_State.ToString().Trim() : ""; party.ACLicense_ID = value.Scale.Customer_ACLicense_ID; party.Party_DOB = value.Scale.Customer_DOB; //string dobString = value.Scale.Customer_DOB; //DateTime dobDt; //if (smART.Common.DateTimeHelper.IsValidDate(dobString, out dobDt)) // party.Party_DOB = dobDt; party = partyLib.Add(party); newScale.Party_ID = party; // Add new Address AddressBook address = new AddressBook(); address.Address1 = value.Scale.Customer_Address; address.City = value.Scale.Customer_City; address.State = value.Scale.Customer_State; address.Country = value.Scale.Customer_Country; address.Party = party; address.Created_By = value.Scale.Created_By; address.Updated_By = value.Scale.Created_By; address.Created_Date = value.Scale.Created_Date; address.Last_Updated_Date = value.Scale.Created_Date; address.Primary_Flag = true; address.Active_Ind = true; address.Zip_Code = value.Scale.Customer_Zip; AddressBookLibrary addressLib = new AddressBookLibrary(ConString); addressLib.Add(address); } } // Save Scale ScaleLibrary lib = new ScaleLibrary(ConString); newScale.Ticket_Status = "Open"; newScale.QScale = true; newScale.Gross_Weight = value.ScaleDetails.Sum(s => s.GrossWeight); newScale.Tare_Weight = value.ScaleDetails.Sum(s => s.TareWeight);; newScale.Net_Weight = value.ScaleDetails.Sum(s => s.NetWeight); value.Scale.MapServiceEntityToServerEntity(newScale); smART.ViewModel.Scale scale = lib.Add(newScale); // Save scale detail if (value.ScaleDetails != null) { ScaleDetailsLibrary libScaleDetail = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); ItemLibrary libItem = new ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); foreach (var item in value.ScaleDetails) { smART.ViewModel.ScaleDetails newScaleDetails = new smART.ViewModel.ScaleDetails(); newScaleDetails.Apply_To_Item = libItem.GetByID(item.Item_ID.ToString()); newScaleDetails.Item_Received = libItem.GetByID(item.Item_ID.ToString()); newScaleDetails.Scale = scale; item.MapServiceEntityToServerEntity(newScaleDetails); ScaleDetails scaleDetails = libScaleDetail.Add(newScaleDetails); // Set docuent related id if document is related to item if (value.ScaleAttachments != null && value.ScaleAttachments.Count > 0) { Model.ScaleAttachments modelAttach = value.ScaleAttachments.Where(w => w.Document_RelatedID == item.ID).FirstOrDefault(); if (modelAttach != null && modelAttach.Document_RelatedTo == 1) { modelAttach.Document_RelatedID = scaleDetails.ID; } } } } // Save Max Ticket ID in Device Settings DeviceSettingLibrary deviceLib = new DeviceSettingLibrary(ConString); DeviceSettings deviceSettings = deviceLib.GetByUniueID(scale.Unique_ID.Value); deviceSettings.MaxTicket_ID = value.Scale.ID; deviceLib.Modify(deviceSettings); // Save Attachments if (value.ScaleAttachments != null) { ScaleAttachmentsLibrary libAttach = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); FilelHelper fileHelper = new FilelHelper(); foreach (var item in value.ScaleAttachments) { smART.ViewModel.ScaleAttachments newScaleAttachment = new smART.ViewModel.ScaleAttachments(); // Save file Guid docRefId = Guid.NewGuid(); string destinationPath = fileHelper.GetSourceDirByFileRefId(docRefId.ToString()); fileHelper.MoveFile(item.Document_Title, fileHelper.GetTempSourceDirByFileRefId(item.Document_Path), destinationPath); // Save attachment newScaleAttachment.Parent = scale; newScaleAttachment.Document_RefId = docRefId; newScaleAttachment.Document_Path = Path.Combine(destinationPath, item.Document_Title); item.MapServiceEntityToServerEntity(newScaleAttachment); libAttach.Add(newScaleAttachment); } } // Complete transaction. scope.Complete(); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { ExceptionHandler.HandleException(ex, "An error occured in SaveTicket."); //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicket", ex.Message, ex.StackTrace.ToString()); //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }