Beispiel #1
0
    public static String SaveEnquiry(App.CustomModels.CustomEnquiry customEnquiry)
    {
        OMMDataContext context = new OMMDataContext();
        Enquiry        enquiry = null;

        if (customEnquiry.ID == 0)
        {
            enquiry = new Enquiry();
            context.Enquiries.InsertOnSubmit(enquiry);
        }
        else
        {
            enquiry = context.Enquiries.SingleOrDefault(P => P.ID == customEnquiry.ID);
        }

        MapEnquiry(customEnquiry, enquiry, context);
        foreach (EnquiryFile file in SessionCache.CurrentEnquiryFiles)
        {
            enquiry.EnquiryFiles.Add(file);
        }
        context.SubmitChanges();
        SaveEnquiryLineItems(customEnquiry, enquiry, context);
        MoveAttachedFiles(enquiry, context);
        SessionCache.CurrentEnquiryFiles = null;
        return(String.Format("{0}:{1}", enquiry.ID, enquiry.Number));
    }
Beispiel #2
0
    /// <summary>
    /// Prepares the object to save with LINQ
    /// </summary>
    /// <param name="customEnquiry"></param>
    /// <param name="context"></param>
    /// <returns></returns>
    private static void MapEnquiry(App.CustomModels.CustomEnquiry customEnquiry, Enquiry enquiry, OMMDataContext context)
    {
        enquiry.ContactID      = customEnquiry.ContactID;
        enquiry.TypeID         = customEnquiry.TypeID;
        enquiry.StatusID       = customEnquiry.StatusID;
        enquiry.EnguirySubject = customEnquiry.EnguirySubject;

        //if(customEnquiry.StatusID == EnquiryStatus.New)
        if (customEnquiry.ID == 0) ///Insert Mode
        {
            enquiry.Number = context.GenerateNewEnquiryNumber(enquiry.TypeID);
            ///Source Type ID will not be editable once set.
            enquiry.SourceTypeID      = customEnquiry.SourceTypeID;
            enquiry.CreatedByUserID   = SessionCache.CurrentUser.ID;
            enquiry.CreatedByUsername = SessionCache.CurrentUser.UserName;
            enquiry.CreatedOn         = DateTime.Now;
        }
        ///Following Data Loggin Should be Done for both Insert and Update
        enquiry.ChangedByUserID   = SessionCache.CurrentUser.ID;
        enquiry.ChangedByUsername = SessionCache.CurrentUser.UserName;
        enquiry.ChangedOn         = DateTime.Now;
    }