コード例 #1
0
        protected override void SaveChildEntities(string[] childEntityList, Scale entity)
        {
            foreach (string ChildEntity in childEntityList)
            {
                switch (ChildEntity)
                {
                    #region /* Case Statements - All child grids */

                case "ScaleDetails":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleDetailsLibrary        ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ScaleDetails> resultList          = (IList <ScaleDetails>)Session[ChildEntity];
                        foreach (ScaleDetails scaleDetails in resultList)
                        {
                            scaleDetails.Scale = new Scale {
                                ID = entity.ID
                            };
                            ScaleDetailsLibrary.Add(scaleDetails);
                        }
                    }
                    break;

                case "ScaleNotes":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleNotesLibrary        ScaleNotesLibrary = new ScaleNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ScaleNotes> resultList        = (IList <ScaleNotes>)Session[ChildEntity];
                        foreach (ScaleNotes ScaleNote in resultList)
                        {
                            ScaleNote.Parent = new Scale {
                                ID = entity.ID
                            };
                            //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes);
                            ScaleNotesLibrary.Add(ScaleNote);
                        }
                    }
                    break;

                case "ScaleAttachments":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleAttachmentsLibrary        ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ScaleAttachments> resultList   = (IList <ScaleAttachments>)Session[ChildEntity];
                        string      destinationPath;
                        string      sourcePath;
                        FilelHelper fileHelper = new FilelHelper();
                        foreach (ScaleAttachments Scale in resultList)
                        {
                            destinationPath     = fileHelper.GetSourceDirByFileRefId(Scale.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
                            sourcePath          = fileHelper.GetTempSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());
                            Scale.Document_Path = fileHelper.GetFilePath(sourcePath);
                            fileHelper.MoveFile(Scale.Document_Name, sourcePath, destinationPath);

                            Scale.Parent = new Scale {
                                ID = entity.ID
                            };
                            ScaleLibrary.Add(Scale);
                        }
                    }
                    break;
                //case "ScaleIDCardAttachments":
                //  if (Session[ChildEntity] != null) {
                //    ScaleIDCardAttachmentsLibrary ScaleLibrary = new ScaleIDCardAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                //    IEnumerable<ScaleIDCardAttachments> resultList = (IList<ScaleIDCardAttachments>) Session[ChildEntity];
                //    string destinationPath;
                //    string sourcePath;
                //    FilelHelper fileHelper = new FilelHelper();
                //    foreach (ScaleIDCardAttachments Scale in resultList) {
                //      destinationPath = fileHelper.GetSourceDirByFileRefId(Scale.Document_RefId.ToString());// Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
                //      sourcePath = fileHelper.GetTempSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());
                //      Scale.Document_Path = fileHelper.GetFilePath(sourcePath);
                //      fileHelper.MoveFile(Scale.Document_Name, sourcePath, destinationPath);

                //      Scale.Parent = new Scale {
                //        ID = entity.ID
                //      };
                //      ScaleLibrary.Add(Scale);
                //    }
                //  }
                //  break;
                case "ScaleExpense":
                    if (Session[ChildEntity] != null)
                    {
                        ScaleExpenseLibrary           lib        = new ScaleExpenseLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        IEnumerable <ExpensesRequest> resultList = (IList <ExpensesRequest>)Session[ChildEntity];
                        foreach (ExpensesRequest exp in resultList)
                        {
                            exp.Reference = new Invoice {
                                ID = entity.ID
                            };
                            exp.Reference_Table = entity.GetType().Name;
                            exp.Reference_ID    = entity.ID;
                            lib.Add(exp);
                        }
                    }
                    break;

                    #endregion
                }
            }
        }
コード例 #2
0
        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));
            }
        }